Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


How to exclude certain file types from a CopyFolder command?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,60910
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to exclude certain file types from a CopyFolder command?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 How to exclude certain file types from a CopyFolder com... - 6/2/2008 4:32:09 AM   
  Stumpedtechy

 

Posts: 41
Score: 0
Joined: 11/30/2007
Status: offline
Currently I am running -

strUserProfile is the user I am backing up.
strServer is where I am backing it up to.

oFilesys.CopyFolder ""&strUserProfile&"\Desktop" , "" & strServer & "\" & oUser & "\" , OverWriteFiles
oFilesys.CopyFolder ""&strUserProfile&"\Favorites" , "" & strServer & "\" & oUser & "\" , OverWriteFiles
oFilesys.CopyFolder ""&strUserProfile&"\My Documents" , "" & strServer & "\" & oUser & "\" , OverWriteFiles

The problem is we have users who love to place MP3, IMG, JPG, EXE  and many other "junk files" in these locations. (I say this since we are on a coporate network and none of these are acceptible per our company policy).

I need to figure out a way to backup these 3 folders (and all subfolders) from the computer to the server with ensuring that specific file types don't get copied from any of the subfolders it may be embedded in.

Can anyone point me in the right direction and hopefully provide me enough of a pointer that I can mesh it into the script I already have?
 
 
Post #: 1
 
 RE: How to exclude certain file types from a CopyFolder... - 6/2/2008 4:34:04 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
Look at a tool called RoboCopy. Otherwise you will have to write code to do the checking yourself. Not hard code to write, but Robocopy already has it all so why reinvent the wheel?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Stumpedtechy)
 
 
Post #: 2
 
 RE: How to exclude certain file types from a CopyFolder... - 6/3/2008 1:34:47 AM   
  Stumpedtechy

 

Posts: 41
Score: 0
Joined: 11/30/2007
Status: offline
Well I was hoping to not rely on another tool to do this but I guess I can't get away from it.

I got this -

cmdString = "cmd /c Robocopy "&strUserProfile&"\Desktop "&strServer&"\"&strUser&"\Desktop /S /XF *.mp3 *.gho *.img *.jpg"

but here is the problem

When ran this retuns - cmd /c Robocopy C:\Documents and Settings\user\Desktop \\Server\Backup Share\User\Desktop /S /XF *.mp3 *.gho *.img *.jpg

The command line does not like spaces without quotes and I need

cmdString = "cmd /c Robocopy "C:\Documents and Settings\user\Desktop" "\\Server\Backup Share\User\Desktop" /S /XF *.mp3 *.gho *.img *.jpg"

If I do any version of double and triple quotes I can't get this string to work.

Any idea on how to get this to work with quotes?

(in reply to Stumpedtechy)
 
 
Post #: 3
 
 RE: How to exclude certain file types from a CopyFolder... - 6/3/2008 1:48:37 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
I may need to add a section on this to the frequently asked stuff thread. Here is the best way that I have found to work out the qotes for a .Run command. Follow this procedure exactly.

1) Open a command prompt
2) In the command prompt, work out exactly how the command needs to look to function from a command line. Once you get it, copy it to the clipboard.
3) Open your favorite VBS editor and create a completely new script file
4) In the editor on the first line put a ' then paste in the command line text that you copied in step 2. This is your goal.
5) Type this into the editor (if you want you can name the shell object whatever it is called in your main script to make things easier later):
   Dim oWsh:Set oWsh = CreateObject("WScript.Shell")
   Dim strCMD
   strCMD = ""
   WScript.Echo strCMD
6) Now change the value of strCMD to be whatever you think would make it be the same as what you copied in ste 2.
7) Run the script
8) Compare the output of the script to the comment that you made on line 1 of the script.
9) Repeat steps 6-8 changing strCMD a little bit at a time until the output of the script is exactly the same as what worked at the command prompt
10) Copy the line that is setting the value of strCMD
11) Paste that into your main script just before where you want to do the .Run command.
12) Change the .Run command in the main script so that it tries to .Run strCMD

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Stumpedtechy)
 
 
Post #: 4
 
 RE: How to exclude certain file types from a CopyFolder... - 6/3/2008 3:17:53 AM   
  Stumpedtechy

 

Posts: 41
Score: 0
Joined: 11/30/2007
Status: offline
I had been doing that myself I was hoping someone knew it right away... anyhow 30 mins of playing led me to -

cmdString2 = "cmd /c Robocopy """&strUserProfile&"\My Documents"" """&strServer&"\"&oUser&"\My Documents"" /S /XF *.mp3 *.gho *.img *.jpg"

I have to say I officially hate double, triple quotes and how poorly they error out with very little information.

I am dreading trying to make *.mp3 *.gho *.img *.jpg a variable I might make the whole thing explode...

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: How to exclude certain file types from a CopyFolder... - 6/3/2008 3:32:14 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
To be honest with you in my opinion if you are trying to do that much exclusion, I would do the whole thing with a RoboCopy JOB file instead of trying to do it at the command line.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Stumpedtechy)
 
 
Post #: 6
 
 RE: How to exclude certain file types from a CopyFolder... - 6/3/2008 3:36:32 AM   
  dm_4ever


Posts: 2665
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
This is how I start out

Copy original to a text editor
   cmd /c Robocopy "C:\Documents and Settings\user\Desktop" "\\Server\Backup Share\User\Desktop" /S /XF *.mp3 *.gho *.img *.jpg
Do a search/replace single " with double " with the editor
   cmd /c Robocopy ""C:\Documents and Settings\user\Desktop"" ""\\Server\Backup Share\User\Desktop"" /S /XF *.mp3 *.gho *.img *.jpg
Add a " before and after
   "cmd /c Robocopy ""C:\Documents and Settings\user\Desktop"" ""\\Server\Backup Share\User\Desktop"" /S /XF *.mp3 *.gho *.img *.jpg"
WScript.Echo this new string to make sure it maches the original
   WScript.Echo  "cmd /c Robocopy ""C:\Documents and Settings\user\Desktop"" ""\\Server\Backup Share\User\Desktop"" /S /XF *.mp3 *.gho *.img *.jpg"
Locate the string I want to replace with a variable
   WScript.Echo  "cmd /c Robocopy ""C:\Documents and Settings\user\Desktop"" ""\\Server\Backup Share\User\Desktop"" /S /XF *.mp3 *.gho *.img *.jpg"
Replace this string value immediately with " & & "
   WScript.Echo  "cmd /c Robocopy ""C:\Documents and Settings\" & & "\Desktop"" ""\\Server\Backup Share\User\Desktop"" /S /XF *.mp3 *.gho *.img *.jpg"
Insert the variable name in between the & &
  
WScript.Echo  "cmd /c Robocopy ""C:\Documents and Settings\" & strVariableGoesHere & "\Desktop"" ""\\Server\Backup Share\User\Desktop"" /S /XF *.mp3 *.gho *.img *.jpg"
Repeat as needed

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Stumpedtechy)
 
 
Post #: 7
 
 RE: How to exclude certain file types from a CopyFolder... - 6/3/2008 3:39:35 AM   
  Stumpedtechy

 

Posts: 41
Score: 0
Joined: 11/30/2007
Status: offline
I would but I want this something modifiable in the script itself. I need to keep this as selfcontained as I can and going with robocopy is already one step out further than I wanted to.

Anyhow bottom line is I got the line I am comfortable with it is -

cmdString = "cmd /c Robocopy """&strUserProfile&"\Desktop"" """&strServer&"\"&oUser&"\Desktop"" /S /XF "&strExclusion&""

The sad part is now reading this line 100% made I see why you need 3 "'s and then 2 "''s the 3 is for the 2 and then the beginning of the variable and the 2 is the to close the 2 before the variable. *smacks head*

(in reply to Stumpedtechy)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to exclude certain file types from a CopyFolder command? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts