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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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