# Batch file to copy files by filename



## yoda_pooh (Oct 9, 2009)

Hello,

I'm a teacher with about 800 students in my school. We have pictures of all students on a network drive, named xxxxxx.jpg where xxxxxx is their individual student number.

I want to use a batch file that will only copy the pictures of the 160 or so students I teach. I already have all of their student numbers in a spreadsheet.

Thank you


----------



## midders (Jan 1, 1970)

Using a spreadsheet formula, create a new column which evaluates to:

```
copy "\\server\path\0123456.jpg" "c:\My Documents\student pics"
```
where \\server\path is the path to your network share (could be mapped to a drive letter etc.)
Select the entire column and then save as a plain text file (newline separated) called something.bat
Create a new folder in My Documents called "student pics"
Click on Start->Run... and browse to your something.bat file. Click on OK.
Eh, voila it should be done.
If it doesn't work, check your quotes carefully; any path that includes spaces needs to be quoted. You can also run the something.bat file from the command line (Start->Run... cmd) to check for error messages, or add the word "pause" (no quotes) after the end of your list of copy commands in the something.bat file, so that you can view the results.

Slainte

midders


----------



## Squashman (Apr 4, 2003)

That is one way to do it. I personally would just dump the excel file to a CSV and then parse the csv with a For Loop.


----------



## midders (Jan 1, 1970)

Squashman said:


> That is one way to do it. I personally would just dump the excel file to a CSV and then parse the csv with a For Loop.


I was going to suggest something along those lines, but using sed; however, with a self-proclaimed status of 'beginner' I thought that the simpler option was the way to go.


----------



## Squashman (Apr 4, 2003)

_Posted via Mobile Device_
SED???
No need to use SED. A basic batch file with a for loop will suffice just fine. Why were you thinking sed?


----------



## midders (Jan 1, 1970)

Squashman said:


> _Posted via Mobile Device_
> SED???
> No need to use SED. A basic batch file with a for loop will suffice just fine. Why were you thinking sed?


Just trying to keep old skills from going too rusty; you know you're a real nerd when you can write a sed pattern first time! I was tinkering with it for a complex renaming task a few days ago, so it's fresh in my mind.


----------



## PatrickMc (Jun 5, 2009)

I like the csv and loop idea. Here is a quick batch script in biterscripting ( http://www.biterscripting.com) .

# Script CopyPics.txt
cd "C:/StudentPictures"
var str list ; cat "MyStudents.csv" > $list
var str student ; lex "1" $list > $student
while ($student <> "")
do
system copy ($student+".jpg") "C:/CopyFolder"
lex "1" $list > $student
done


----------

