+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
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 ...
  1. #1

    Join Date
    Aug 2007
    Posts
    812
    Thank Post
    98
    Thanked 64 Times in 46 Posts
    Rep Power
    26

    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

  2. #2
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    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.

  3. #3

    Join Date
    Aug 2007
    Posts
    812
    Thank Post
    98
    Thanked 64 Times in 46 Posts
    Rep Power
    26
    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.

  4. #4
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    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.

  5. #5

    Join Date
    Aug 2007
    Posts
    812
    Thank Post
    98
    Thanked 64 Times in 46 Posts
    Rep Power
    26
    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

  6. #6
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    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?

  7. #7

    Join Date
    Aug 2007
    Posts
    812
    Thank Post
    98
    Thanked 64 Times in 46 Posts
    Rep Power
    26
    Correct thankyou

    So you would be using xcopy in a batch script?

  8. #8
    apeo's Avatar
    Join Date
    Sep 2005
    Location
    Lost
    Posts
    1,612
    Thank Post
    95
    Thanked 115 Times in 111 Posts
    Rep Power
    42
    Quote Originally Posted by burgemaster View Post
    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.

  9. Thanks to apeo from:

    burgemaster (14th June 2010)

  10. #9

    Join Date
    Aug 2007
    Posts
    812
    Thank Post
    98
    Thanked 64 Times in 46 Posts
    Rep Power
    26
    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.

  11. #10
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,999
    Thank Post
    120
    Thanked 280 Times in 258 Posts
    Rep Power
    106
    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

  12. Thanks to ChrisH from:

    burgemaster (14th June 2010)

  13. #11

    Join Date
    Aug 2007
    Posts
    812
    Thank Post
    98
    Thanked 64 Times in 46 Posts
    Rep Power
    26
    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

  14. #12
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,999
    Thank Post
    120
    Thanked 280 Times in 258 Posts
    Rep Power
    106
    The command line is wrong then try doing it manually from the the command prompt. Does the "/o" want to got after strLocationXCopy?

  15. #13
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,999
    Thank Post
    120
    Thanked 280 Times in 258 Posts
    Rep Power
    106
    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

  16. #14

    Join Date
    Aug 2007
    Posts
    812
    Thank Post
    98
    Thanked 64 Times in 46 Posts
    Rep Power
    26
    Quote Originally Posted by ChrisH View Post
    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)

  17. #15
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,999
    Thank Post
    120
    Thanked 280 Times in 258 Posts
    Rep Power
    106
    Look at my second post and try that sometimes it just works doing it that way.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

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
  •