Link to home
Start Free TrialLog in
Avatar of aceklub97
aceklub97

asked on

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

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?

 
Avatar of Kentrix70
Kentrix70
Flag of Denmark image

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
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

Avatar of aceklub97
aceklub97

ASKER


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_*.*"")
ASKER CERTIFIED SOLUTION
Avatar of NicksonKoh
NicksonKoh
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help.  That worked and I can use work with that.