Scripts Thread, REQUEST: Script 2 copy from multiple source folders 2 one folder BUT keep permissions in Coding and Web Development; As srochford has kindly sorted my other script, I can now move all of the students MP3 out of their ...
-
13th June 2010, 09:01 PM #1 REQUEST: Script 2 copy from multiple source folders 2 one folder BUT keep permissions
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
-
-
IDG Tech News
-
14th June 2010, 08:32 AM #2 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.
-
-
14th June 2010, 09:36 AM #3 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.
-
-
14th June 2010, 10:08 AM #4 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.
-
-
14th June 2010, 10:18 AM #5 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
-
-
14th June 2010, 11:24 AM #6 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?
-
-
14th June 2010, 01:56 PM #7 Correct thankyou 
So you would be using xcopy in a batch script?
-
-
14th June 2010, 03:32 PM #8 
Originally Posted by
burgemaster
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:
Code:
strSourceFolder = "<Source Folder>" 'eg d:\users\students
strDestFolder = "<Destination Folder>" 'eg d:\share
strLocationXcopy = "<Path to xcopy>" '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.
-
Thanks to apeo from:
burgemaster (14th June 2010)
-
14th June 2010, 06:22 PM #9 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:
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
wshShell.run strLocationXcopy & " '" & objFile.path "' " & "'" & strDestFolder & "' /o"
End If
Next
for each objFolder in objFolder.SubFolders
GetFiles objFolder.Path
next
end sub
Last edited by ChrisH; 14th June 2010 at 06:35 PM.
-
-
14th June 2010, 06:45 PM #10 You are missing an ampersand
Code:
wshShell.run strLocationXcopy & " '" & objFile.path "' " & "'" & strDestFolder & "' /o"
should be
Code:
wshShell.run strLocationXcopy & " '" & objFile.path & "' " & "'" & strDestFolder & "' /o"
its the bit after objFile.path
-
Thanks to ChrisH from:
burgemaster (14th June 2010)
-
14th June 2010, 07:06 PM #11 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
-
-
14th June 2010, 07:08 PM #12 The command line is wrong then try doing it manually from the the command prompt. Does the "/o" want to got after strLocationXCopy?
-
-
14th June 2010, 07:12 PM #13 Also I never like concatenating a string in the run statement, especially when dealing with cmdline apps. try
Code:
If right(objFile.path,3) = "mp3" Then
strCmdLine = strLocationXcopy & " '" & objFile.path "' " & "'" & strDestFolder & "' /o"
wshShell.run strCmdLine
End If
-
-
14th June 2010, 07:14 PM #14 
Originally Posted by
ChrisH
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)
-
-
14th June 2010, 07:15 PM #15 Look at my second post and try that sometimes it just works doing it that way.
-
SHARE: 
Similar Threads
-
By tosca925 in forum Scripts
Replies: 3
Last Post: 26th October 2012, 02:15 PM
-
By Optimus in forum Windows
Replies: 2
Last Post: 18th March 2010, 10:38 AM
-
By ZeroHour in forum Windows Vista
Replies: 1
Last Post: 9th June 2008, 04:09 PM
-
By JPhillips173 in forum Scripts
Replies: 2
Last Post: 17th April 2008, 11:25 AM
-
By AlexPilot 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
-
Forum Rules