+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
Scripts Thread, REQUEST: Script 2 copy from multiple source folders 2 one folder BUT keep permissions in Coding and Web Development; Lets try a little debugging to see if any paths look wrong or anything. This will pop up a box ...
  1. #16
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,995
    Thank Post
    120
    Thanked 280 Times in 258 Posts
    Rep Power
    106
    Lets try a little debugging to see if any paths look wrong or anything. This will pop up a box and not do any copying.

    Code:
    strSourceFolder = "\\nas\Student_Drives\05\teststudent\My Music" 'eg d:\users\students
    strDestFolder = "\\nas\Student_media\Music Files" 'eg d:\share
    strLocationXcopy = "c:\xcopy.exe" 'eg c:\xcopy.exe
    
    set objFSO = createobject("Scripting.FileSystemObject")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    
    GetFiles strSourceFolder
    
    sub GetFiles(byval strDirectory)
    	set objFolder = objFSO.GetFolder(strDirectory)
    	for each objFile in objFolder.Files
    		If right(objFile.path,3) = "mp3" Then
    			strCmdLine = strLocationXcopy & " '" & objFile.path & "' " & "'" & strDestFolder & "' /o"
    Wscript.echo strCmdLine
    'wshShell.run  strCmdLine
    		End If 
    	Next	
    	for each objFolder in objFolder.SubFolders
    		GetFiles objFolder.Path
    	next
    end sub
    Last edited by ChrisH; 14th June 2010 at 07:23 PM.

  2. #17

    Join Date
    Aug 2007
    Posts
    811
    Thank Post
    98
    Thanked 64 Times in 46 Posts
    Rep Power
    25
    Quote Originally Posted by ChrisH View Post
    Look at my second post and try that sometimes it just works doing it that way.
    Popups appear alot faster than before but still contain "Invalid Number of parameters"

    Also did you cut and paste from original post and not mean to miss out the & after objFile.path ?

    Thanks
    Tim

  3. #18

    Join Date
    Aug 2007
    Posts
    811
    Thank Post
    98
    Thanked 64 Times in 46 Posts
    Rep Power
    25
    It looks good apart from it has single ' instead of " on the file paths? is that allowed?

    Output:
    c:\xcopy.exe '\\nas\Student_Drives\05\teststudent\My Music\Skindred - Nobody.mp3' '\\nas\Student_media\Music Files' /o
    Last edited by burgemaster; 14th June 2010 at 07:27 PM.

  4. #19
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,995
    Thank Post
    120
    Thanked 280 Times in 258 Posts
    Rep Power
    106
    Try this line instead
    Code:
    strCmdLine = strLocationXcopy & " " & chr(34) & objFile.path & chr(34) & " "  & chr(34) & strDestFolder & chr(34) & " /o"

  5. #20

    Join Date
    Aug 2007
    Posts
    811
    Thank Post
    98
    Thanked 64 Times in 46 Posts
    Rep Power
    25
    Chris thanks so much !!
    This is now 99% working !!!!

    It is copying all the files perfectly, but it is NOT copying the permissions over....
    It is copying the "Owner" which i guess is the /o switch.

    MS say "To preserve permissions when files and folders are copied or moved, use the Xcopy.exe utility with the /O or the /X switch"
    I have also tried swapping to X, still no good

    But I think the scripting part is doing its job!
    Thanks again

    Script now:

    strSourceFolder = "\\nas\Student_Drives\05\teststudent\My Music" 'eg d:\users\students
    strDestFolder = "\\nas\Student_media\Music Files\" 'eg d:\share
    strLocationXcopy = "c:\xcopy.exe" 'eg c:\xcopy.exe

    set objFSO = createobject("Scripting.FileSystemObject")
    Set WshShell = WScript.CreateObject("WScript.Shell")

    GetFiles strSourceFolder

    sub GetFiles(byval strDirectory)
    set objFolder = objFSO.GetFolder(strDirectory)
    for each objFile in objFolder.Files
    If right(objFile.path,3) = "mp3" Then
    strCmdLine = strLocationXcopy & " " & chr(34) & objFile.path & chr(34) & " " &chr(34 )& strDestFolder & chr(34) &" /o" &" /x"
    wshShell.run strCmdLine
    End If
    Next
    for each objFolder in objFolder.SubFolders
    GetFiles objFolder.Path
    next
    end sub

  6. #21
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,995
    Thank Post
    120
    Thanked 280 Times in 258 Posts
    Rep Power
    106
    I prefer robocopy to preserve permissions.

  7. #22

    Join Date
    Aug 2007
    Posts
    811
    Thank Post
    98
    Thanked 64 Times in 46 Posts
    Rep Power
    25
    Quote Originally Posted by ChrisH View Post
    I prefer robocopy to preserve permissions.
    I think it must be my permissions on the destination folder as it works perfectly when set to: C:\files

    Thanks for all your help mate!!!

  8. #23
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    41
    Nice one ChrisH.. debugged my buggy script. Sorry burgemaster, i should have checked it for ya and i did wonder if the command would accept ' instead of ", my bad. FYI permission will move fine if its drive to drive on the same machine, you dont even need to use xcopy to do it e.g. vbs command objfso.movefile could work. I dont think this would make a difference but you could try mapping the drives.

    ChrisH does have a good point about RoboCopy.

  9. Thanks to apeo from:

    burgemaster (15th June 2010)

SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 3
    Last Post: 26th October 2012, 02:15 PM
  2. Multiple folders in a folder
    By Optimus in forum Windows
    Replies: 2
    Last Post: 18th March 2010, 10:38 AM
  3. editing multiple folder permissions
    By ZeroHour in forum Windows Vista
    Replies: 1
    Last Post: 9th June 2008, 04:09 PM
  4. Replies: 2
    Last Post: 17th April 2008, 11:25 AM
  5. Write but not view folder permissions, strange request
    By HMCTech in forum Windows Server 2008
    Replies: 7
    Last Post: 14th April 2008, 01:21 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •