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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now