none
copy file into multiple folders

    Question

  • W2K3 AD Domain, XP Pro PCs.
     
    I work as a teacher and frequently need to copy files (students assigned
    work) into multiple folders (one for each student).
     
    The students have an individual directory under each class they are a member
    of.
     
    Please could anyone let me know how to achieve this efficiently, perhaps
    using a batch file to automate the process.
     
    Thanks, Anastas
     
     
    Monday, November 08, 2010 7:27 PM

Answers

  • Assuming that each student is represented by a subfolder in the "Class 1" folder, the following should work:

    @echo off
    for  /D  %%a  in ("c:\Class 1\*.*") do xcopy  /y  /d  c:\test\work.txt "%%a\"

    Note also:
    - The batch file you proposed will not work in its posted form because of the space in the target folder name.
    - I strongly recommend you use the /Y and /D switches for the xcopy command.

    Monday, November 08, 2010 9:00 PM

All replies

  • The usual method is to automate the process by inserting an appropriate instruction into the logon script or by setting some domain policy. It is hard to be specific in the absence of any detail but here is the style of copy instruction you would use:

    xcopy  /d  /y  /c  "\\Server\Share\Folder\File.ext"  "%UserProfile%\Desktop\TargetFolder\"  > nul

    When you type xcopy /? at the Command Prompt then you will see the meaning of the various switches.

    Monday, November 08, 2010 7:33 PM
  • Here's a bit of PowerShell to do it if you want to supply a list of student names:

    $source = "\\server\share\folderwherefilesare\*.*"
    $dest = "\\server\share\class\"
    
    $students = @("Doug","Bill","Alfonso")
    
    $students |foreach {
      copy $source (join-path $dest $_)
    }

    http://twitter.com/toenuff
    write-host ((0..56)|%{if (($_+1)%3 -eq 0){[char][int]("116111101110117102102064103109097105108046099111109"[($_-2)..$_] -join "")}}) -separator ""
    Monday, November 08, 2010 7:51 PM
  • Hi Pegasus,
     
    Thanks for the reply.
     
    This batch file does the job I want:
     
    xcopy c:\test\work.txt c:\class 1\student_a
    xcopy c:\test\work.txt c:\class 1\student_b
    xcopy c:\test\work.txt c:\class 1\student_c
    ...
    xcopy c:\test\work.txt c:\class 1\student_z
     
    However it is very inelegant. Is there a way to write it so that it does not have to repeat the xcopy command for each pupil?
     
    Thank you for your patience,
     
    Regards, Anastas
    "Pegasus [MVP]" wrote in message news:526db1b1-91fb-4a05-abd3-d99a9624578f...

    The usual method is to automate the process by inserting an appropriate instruction into the logon script or by setting some domain policy. It is hard to be specific in the absence of any detail but here is the style of copy instruction you would use:

    xcopy  /d  /y  /c  "\\Server\Share\Folder\File.ext"  "%UserProfile%\Desktop\TargetFolder\"  > nul

    When you type xcopy /? at the Command Prompt then you will see the meaning of the various switches.

    Monday, November 08, 2010 8:34 PM
  • Hi Tome,
     
    Thank you for the reply.
     
     
    "Tome Tanasovski" wrote in message news:465d3011-7628-4b3e-8b4f-422c475a623e...

    Here's a bit of PowerShell to do it if you want to supply a list of student names:

    $source = "\\server\share\folderwherefilesare\*.*"
    $dest = "\\server\share\class\"
    
    $students = @("Doug","Bill","Alfonso")
    
    $students |foreach {
     copy $source (join-path $dest $_)
    }

    http://twitter.com/toenuff
    write-host ((0..56)|%{if (($_+1)%3 -eq 0){[char][int]("116111101110117102102064103109097105108046099111109"[($_-2)..$_] -join "")}}) -separator ""
    Monday, November 08, 2010 8:48 PM
  • Assuming that each student is represented by a subfolder in the "Class 1" folder, the following should work:

    @echo off
    for  /D  %%a  in ("c:\Class 1\*.*") do xcopy  /y  /d  c:\test\work.txt "%%a\"

    Note also:
    - The batch file you proposed will not work in its posted form because of the space in the target folder name.
    - I strongly recommend you use the /Y and /D switches for the xcopy command.

    Monday, November 08, 2010 9:00 PM
  • Hi Pegasus,
     
    That worked beautifully.
     
    I am really grateful because you have saved so much future lesson prep time,
     
    Thank you,
     
    Anastas.
    "Pegasus [MVP]" wrote in message news:4b84dfee-506e-4cb0-8e4d-dc8629963f7a...

    Assuming that each student is represented by a subfolder in the "Class 1" folder, the following should work:

    @echo off
    for  /D  %%a  in ("c:\Class 1\*.*") do xcopy  /y  /d  c:\test\work.txt "%%a\"

    Note also:
    - The batch file you proposed will not work in its posted form because of the space in the target folder name.
    - I strongly recommend you use the /Y and /D switches for the xcopy command.

    • Proposed as answer by ILoveOberwald Wednesday, May 23, 2012 8:33 PM
    Monday, November 08, 2010 9:29 PM
  • Thanks for the feedback. Please mark my reply as "Answer".
    • Proposed as answer by ILoveOberwald Wednesday, May 23, 2012 8:33 PM
    Monday, November 08, 2010 9:41 PM