[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
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
Medium Priority
?
1,193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 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