burgemaster Posted June 13, 2010 Posted June 13, 2010 As srochford has kindly sorted my other script, I can now move all of the students MP3 out of their home drives to a shared folder. I want to move all MP3`s that students have from any folder in their homedrives ( N: ) to a single folder on the common drive. e.g (O:\Student Music\Year 9) I need to also copy the permissions (or just owner), so that my other new script can then rename the files from maybe mysong.mp3 to 09Jack.Jones_mysong.mp3 Ive found that xcopy can copy the permissions with the /o switch. and xxcopy can copy from multiple directories to a single folder. But both cant do both (i think) Can anyone please suggest a way I can do this? Thanks in advance
apeo Posted June 14, 2010 Posted June 14, 2010 Why you need to copy multiple directories? I've not looked at your other script but i imagine it would recursively go throught all folders and rename all the mp3. Could you not just move it after its been renamed or even copy it to the desired location but with the desired name. This way you wouldnt need to copy the permissions.
burgemaster Posted June 14, 2010 Author Posted June 14, 2010 Hi mate, Students will hide there MP3 collection in eg. N:/school work/ict/homework/dont go in here/music..... I want to be able to move them from all these various directories to one central location. For the other script that renames it needs to read the owner of the file. If I copy it would replace me as the owner. If i was to rename first, then when they are moved it would then ammend myself as the owner when the script next runs.
apeo Posted June 14, 2010 Posted June 14, 2010 Think I'm being abit slow today.. put it down to the Mondays. From what you said, theres an issue with renaming it first then moving it because when its moved you are the owner and therefore when the script runs again your name will be used.. why does the rename script need to be run twice? The way i say it this is what should happen: For all files in directory if .mp3 then copy file to desired location (process of coping will rename file e.g. copy file.mp3 O:\directory\newfile.mp3) Delete file end if loop Thats what i think it should do.. atleast in pseudo. maybe i could look at your other script and i could adapt that one.
burgemaster Posted June 14, 2010 Author Posted June 14, 2010 hehe, The rename Script will be run regularly in that share, as in the future the only place that they will be able to save MP3 files to will be the new share. So they copy a file into there and it then gets renamed. This script will only be run once to MOVE all their current MP3 files. Thanks Tim
apeo Posted June 14, 2010 Posted June 14, 2010 Ah right ok, i didnt get why you needed to run the rename script more then once. No probs, the pseudo should look something like this then: for all files in directory if .mp3 then xcopy file to desired location (i think xcopy keeps the permissions intact) delete file end if loop Is this what you want to happen?
burgemaster Posted June 14, 2010 Author Posted June 14, 2010 Correct thankyou So you would be using xcopy in a batch script?
apeo Posted June 14, 2010 Posted June 14, 2010 Correct thankyou So you would be using xcopy in a batch script? Im more a vbs guy so this is the script i'd probably use: strSourceFolder = "" 'eg d:\users\students strDestFolder = "" 'eg d:\share strLocationXcopy = "" '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 wshShell.run strLocationXcopy & " '" & objFile.path "' " & "'" & strDestFolder & "' /o" End If Next for each objFolder in objFolder.SubFolders GetFiles objFolder.Path next end sub btw its untested so please test it first before you run it for real. 1
burgemaster Posted June 14, 2010 Author Posted June 14, 2010 (edited) great stuff !! thankyou for trying this for me, I dont know where id be without all you edugeek scripting experts! Unfortunetly im getting: Script: C:\test.vbs Line: 14 Char: 56 Error: Expected end of statement Code: 800a0401 Source: MS VBScript Compilation Error hope this means more to you than it does to me!!! Heres the exact code I used: 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 wshShell.run strLocationXcopy & " '" & objFile.path "' " & "'" & strDestFolder & "' /o" End If Next for each objFolder in objFolder.SubFolders GetFiles objFolder.Path next end sub Edited June 14, 2010 by ChrisH
ChrisH Posted June 14, 2010 Posted June 14, 2010 You are missing an ampersand wshShell.run strLocationXcopy & " '" & objFile.path "' " & "'" & strDestFolder & "' /o" should be wshShell.run strLocationXcopy & " '" & objFile.path & "' " & "'" & strDestFolder & "' /o" its the bit after objFile.path 1
burgemaster Posted June 14, 2010 Author Posted June 14, 2010 Were getting somewhere thankyou Now getting lots of cmd windows opening and closing, but they are all failing with "Invalid Number of parameters" Nothing gets copied
ChrisH Posted June 14, 2010 Posted June 14, 2010 The command line is wrong then try doing it manually from the the command prompt. Does the "/o" want to got after strLocationXCopy?
ChrisH Posted June 14, 2010 Posted June 14, 2010 Also I never like concatenating a string in the run statement, especially when dealing with cmdline apps. try If right(objFile.path,3) = "mp3" Then strCmdLine = strLocationXcopy & " '" & objFile.path "' " & "'" & strDestFolder & "' /o" wshShell.run strCmdLine End If
burgemaster Posted June 14, 2010 Author Posted June 14, 2010 The command line is wrong then try doing it manually from the the command prompt. Does the "/o" want to got after strLocationXCopy? XCOPY source [destination] option xcopy "\\nas\Student_Drives\05\teststudent\My Music" "\\nas\Student_media\Music Files" /o works fine.... must be a problem with the script (i think)
ChrisH Posted June 14, 2010 Posted June 14, 2010 Look at my second post and try that sometimes it just works doing it that way.
ChrisH Posted June 14, 2010 Posted June 14, 2010 (edited) 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. 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 Edited June 14, 2010 by ChrisH
burgemaster Posted June 14, 2010 Author Posted June 14, 2010 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
burgemaster Posted June 14, 2010 Author Posted June 14, 2010 (edited) 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 Edited June 14, 2010 by burgemaster
ChrisH Posted June 14, 2010 Posted June 14, 2010 Try this line instead strCmdLine = strLocationXcopy & " " & chr(34) & objFile.path & chr(34) & " " & chr(34) & strDestFolder & chr(34) & " /o"
burgemaster Posted June 14, 2010 Author Posted June 14, 2010 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
burgemaster Posted June 14, 2010 Author Posted June 14, 2010 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!!!
apeo Posted June 15, 2010 Posted June 15, 2010 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. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now