Question:
Batch file that looks for and copies all .jpg files?
Benzymo
2011-11-13 08:38:09 UTC
Looking for a batch file that looks for all .jpg files, or whatever you set it to look for. Don't really know how to do it, and looked on the web and couldn't find anything. Is it possible? Does anyone know the command line for something like this?
Five answers:
brisray
2011-11-13 10:17:27 UTC
XCopy is capable of searching all subdirectories of a hard drive. A lot of DOS commands can. Robocopy and Dir are just two other examples.



See http://technet.microsoft.com/en-us/library/bb491035.aspx and see what the E, S and T switches do.



Here's a simple batch file that will do what you want



mkdir c:\test

dir C:\Users\YOUR_NAME\*.jpg /b /s > c:\test\output.txt

for /F "tokens=*" %%a in (c:\test\output.txt) DO copy "%%a" C:\test



mkdir - makes a new directory

the dir command looks for all jpg files in your computer profile and creates a text file listing all the files found

The for command uses the text file made to find and copy all the files in the list that dir made to the directory you made in the first line.



There are methods of writing this all one line where you use the output of the dir command as the input to another command. Read up on "pipes" and "redirection" in batch files and DOS



Unless you have some overiding need to use a batch file then simply use Windows search feature.
BigWhiskey
2011-11-13 08:43:54 UTC
You really don't need a batch file to do this. I used to love DOS but it's easier now to do this with Windows Explorer. Simply open Windows Explorer and click on the drive letter you wish to search (most often it'll be 'C:'). Then in the upper right hand corner of Windows Explorer, type *.jpg



This will search the hard drive for all JPG files and list them on the right panel. If you wish to copy them all, wait until the search is over, use 'Ctrl + A' to select them all and then Ctrl+C to copy them to the new location. :)
oops
2011-11-13 08:43:19 UTC
copy *.jpg dest



dest being the destination directory. This only copies the jpg files in the current directory. Were you looking for something more than that?
anonymous
2016-09-16 06:17:07 UTC
I'm sorry I don't know about this
Bay'sMommy*
2011-11-13 10:13:02 UTC
sooooo.... ummm wdu need this for?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...