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
  • Hi, could you help me apply this code to my folder? I tried making a .bat file with this code but I got the "Invalid number of parameters" error message. I'll list my code below.

    @echo off

    for  /D  %%a  in (\\SERVER0001\TMP_DATA\"TMP\\Southeast Power Pads") do xcopy  /y  /d  \\SERVER0001\TMP_DATA\"TMP\Southeast Power Pads\1.0 Blank Folder\PowerTerm Resource Updater.bat" "%%a\"

    pause

    Are my quotes wrong or something?

    • Proposed as answer by MS61 Tuesday, August 09, 2016 8:35 PM
    • Unproposed as answer by MS61 Tuesday, August 09, 2016 8:35 PM
    Tuesday, August 09, 2016 7:52 PM
  • Hi, could you help me apply this code to my folder? I tried making a .bat file with this code but I got the "Invalid number of parameters" error message. I'll list my code below.

    @echo off

    for  /D  %%a  in (\\SERVER0001\TMP_DATA\"TMP\\Southeast Power Pads") do xcopy  /y  /d  \\SERVER0001\TMP_DATA\"TMP\Southeast Power Pads\1.0 Blank Folder\PowerTerm Resource Updater.bat" "%%a\"

    pause

    Are my quotes wrong or something?

    Sorry to say so but there are so many things wrong with your command that it is difficult to work out what you're trying to do. Let's break it down into small components:

    • You're trying to copy something from the folder "\\Server0001\Tmp_Data\Southeast Power Pads". Is it subfolders you're trying to copy or is it files?
    • Double quotes should surround the whole file specification. You must not insert them in random places inside a path.
    • What is the purpose of the double backslash after TMP?
    • What exactly is your target folder?
    Tuesday, August 09, 2016 9:01 PM
  • I just tried it on a folder that doesn't have spaces in it and it worked like a charm. Now I feel stupid because I set all of these folders up for people with spaces in the names and I can't use this awesome line of script. Instead, I have to write out a line of code for each person's name. Lesson learned the hard way I guess :(
    Tuesday, August 09, 2016 10:31 PM
  • Now I feel stupid because I set all of these folders up for people with spaces in the names and I can't use this awesome line of script. Instead, I have to write out a line of code for each person's name.
    This is not correct. When you place your double quotes correctly then the script will work with any folder name.
    Wednesday, August 10, 2016 5:55 AM