Solved

VBScript - using fso.CopyFile to create a subfolder in a directory and copying several files into that subdirectory

Posted on 2009-04-05
5
1,164 Views
Last Modified: 2012-05-06
Greeting,
I was wondering if someone could help me. I am trying to 1. use the copy function to copy several different individual files from different directories 2. Create a sub directory in the backup directory, 3. copy all the fils into that subfolder.

The problem that I am running into is as follows:

1.  When I use
fso.CopyFile "C:\Programs\Extra\*.ini" , strBackupFolder

It will copy all fifty or so files loose into the directory, and that is a problem, because I don't want to get them mixed up with other .ini files from.

2.  When I use
fso.CopyFolder strSessionsPath , folder.path & "\LogFiles", True
It will create the subdirectory that I want, "LogFiles" in the strBackupFolder,  but then I have to copy the entire folder over.  This won't work either, because the source folder is over 2GB.
Is there any method that I can use where I am using the copyfile method, but still able to create the subdirectory and copy the files to it?

 
0
Comment
Question by:aceklub97
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:Kentrix70
ID: 24074698
You could use the date variable to make an unique folder every day.
Or if you want to run it more than once a day, you could use date & time.

Try making a script with these 3 lines:

wscript.echo date
wscript.echo time
wscript.eco date & " " & time

You can of course, if you want no space between the date and the time
juse make the third line, like this

wscript.echo date & time
0
 
LVL 17

Expert Comment

by:NicksonKoh
ID: 24075067
Hi,

Sorry, I don't exactly catch 100% of what you are trying to achieve. But I am guessing xcopy is what you want.

Check out the code to execute xcopy from vbscript.
DIM objShell
set objShell = wscript.createObject("wscript.shell")
'The dos window will not close. Good for debugging.
iReturn = objShell.Run("CMD /K xcopy c:\temp\test c:\temp\backup /e /y >C:\temp\test.log")
'The dos window will close. Good for production run.
'iReturn = objShell.Run("CMD /C xcopy c:\temp\test c:\temp\backup /e /y >C:\temp\test.log")

Open in new window

0
 

Author Comment

by:aceklub97
ID: 24080160

Ok I am making progress, but I am not used to using the DOS, so bear with me.  This is what I have.  I already have a backup folder set up as strBackupFolder, and I am trying to create a subfolder named XactimateDB with the contacts of the source folder copied into this subfolder.  I think that I still have some syntax wrong.

Dim Shell, ireturn, xactimateDBPathFolder
xactimateDBPathFolder = "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\"

Set shell   = wscript.createobject("wscript.shell")
'iReturn = Shell.Run("CMD /C xcopy xactimateDBPathFolder strBackupFolder & "\XactimateDB" /e /y >"C:\program files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\xm8_*.*"")
0
 
LVL 17

Accepted Solution

by:
NicksonKoh earned 500 total points
ID: 24083140
Hi,

I corrected the last line of the code. Let me know if it is wrong. You can use msgbox to check the string in the Shell.Run.

MsgBox("CMD /C xcopy """ & xactimateDBPathFolder & """ """ & strBackupFolder & "\XactimateDB"" /e /y >""C:\program files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\xm8_*.*""")
iReturn = Shell.Run("CMD /C xcopy """ & xactimateDBPathFolder & """ """ & strBackupFolder & "\XactimateDB"" /e /y >""C:\program files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\xm8_*.*""")

Dim Shell, ireturn, xactimateDBPathFolder
xactimateDBPathFolder = "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\"
 
Set shell = wscript.createobject("wscript.shell")
 
MsgBox("CMD /C xcopy """ & xactimateDBPathFolder & """ """ & strBackupFolder & "\XactimateDB"" /e /y >""C:\program files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\xm8_*.*""")
iReturn = Shell.Run("CMD /C xcopy """ & xactimateDBPathFolder & """ """ & strBackupFolder & "\XactimateDB"" /e /y >""C:\program files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\xm8_*.*""")

Open in new window

0
 

Author Closing Comment

by:aceklub97
ID: 31566901
Thanks for the help.  That worked and I can use work with that.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question