You are here:

Windows 7/Copying certain files quicker

Advertisement


Question
QUESTION: I am working on a project that I feel could probably be done much quicker than I am doing it. Please note, I am good within software but not so much with systems.  I have an excel spreadsheet with a list of over 3700 part numbers. I also have an external hard drive with multiple folders that have photographs of these parts.  I need to find the photos for each of these part numbers and move them to another folder. The photos are named with the part number and additional information if there are multiples. Example 10282710.jpg, 10282710-1Primary.jpg, 10282710-1Alternate.jpg.  

I am currently doing a quick search with the number 10282710 on the search within the main folder, then dragging the photos to a folder on my desktop.

Please note, there may also be photos called 22-10282710.jpg, which I do not want.

Is there a quicker way to do this other than searching for photos one at a time?

Thanks.

ANSWER: Hi there

I should think you could do this by a DOS batch script, you should be able to use your list of part numbers in the excel spread sheet and have the batch script scan through it and then scan the drives/folders for the matching numbers.


I would copy your partno column into a text file and save it as partno.txt, then write a batch file using notepad, you have to save it as .bat

FOR /F %%A IN (partno.txt) DO (
    set partno=%%A
)
c:
md %partno%
CD to the directory or drive where the jpgs are
FOR /F "tokens=*" %%A IN ('dir /b /a-d /s %partno%.jpg') DO copy "%%A" C:\%partno%\

this isn't quite finished because you will need to tell me where your jpgs are, that is how many drives will need to be searched and you will also need to decide where you want them end up.. If you want to try experimenting yourself then I would try just a couple of partnos to see if you can get it to work.

Let me know if you want to carry on and i'll try to help, DOS can be a pain sometimes.


scott



---------- FOLLOW-UP ----------

QUESTION: Yes please, I'd like more help. .  x 221. I've done DOS commands a couple of times, but I will admit it scares me.

The original files are in an external drive identified as E:\. There are four subfolders in this drive.  I am copying some of files to a folder on my desktop for safety sake. C:\Users\Francyn\Desktop\GM-Photos

I am copying the selected jpgs to C:\Users\Francyn\Desktop\ACD Photo Request

The Excel file has been saved as a .txt and is located C:\Users\Francyn\Documents\Paul Work\Parts Lists\2013-12-04 Remaining.txt

I'd like to try, but I will need some "dummy" directions.

Thanks!

ANSWER: Evening

I have put something together for you.

on your e:\ drive  make a folder called "script"

in the folder called script make a text file called partno.txt.  copy your partnumbers from your excel sheet and past them in(you might want to try only 3 different numbers just to test),  your part numbers must show as a column on the left.


go to start and run notepad, copy and past the following:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

md C:\Users\Francyn\Desktop\ACD Photo Request
SET "DEST_DIR=C:\Users\Francyn\Desktop\ACD Photo Request"
SET "SEARCH_DIR=c:\pic1"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
   FOR /R "%SEARCH_DIR%" %%f IN (*%%a*) DO (
       SET "SRC=%%~dpf"
       SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
       xcopy /S /I "%%~f" "!DEST!"
   )
)


SETLOCAL ENABLEDELAYEDEXPANSION

SET "DEST_DIR=C:\Users\Francyn\Desktop\ACD Photo Request"
SET "SEARCH_DIR=c:\pic2"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
   FOR /R "%SEARCH_DIR%" %%f IN (*%%a*) DO (
       SET "SRC=%%~dpf"
       SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
       xcopy /S /I "%%~f" "!DEST!"
   )
)


SETLOCAL ENABLEDELAYEDEXPANSION

SET "DEST_DIR=C:\Users\Francyn\Desktop\ACD Photo Request"
SET "SEARCH_DIR=c:\pic3"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
   FOR /R "%SEARCH_DIR%" %%f IN (*%%a*) DO (
       SET "SRC=%%~dpf"
       SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
       xcopy /S /I "%%~f" "!DEST!"
   )
)

SETLOCAL ENABLEDELAYEDEXPANSION

SET "DEST_DIR=C:\Users\Francyn\Desktop\ACD Photo Request"
SET "SEARCH_DIR=c:\pic4"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
   FOR /R "%SEARCH_DIR%" %%f IN (*%%a*) DO (
       SET "SRC=%%~dpf"
       SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
       xcopy /S /I "%%~f" "!DEST!"
   )
)


PLEASE NOTE:

the above will search through 4 directories, I wasn't sure what they were on your drive so I have called them:

c:\pic1
c:\pic2
c:\pic3
c:\pic4

go through the above script and replace these with the actual directories on your e:\ drive
you then need to "save as" "scrip.bat" and "all filetypes" in the e:\script directory

make sure you put only about 3 part numbers in partno.txt and run the script.bat let me know what happens.

regards

scott
 


---------- FOLLOW-UP ----------

Screenshot
Screenshot  
QUESTION: I was able to do everything as explained and ran the script, but in the script folder, two folders were created: Photo and Request. Unfortunately, both were empty.  I double checked that there were actually photos with these numbers and there were. In the txt file was the pn "21010589", the actual photo file was called "21010589_Primary.JPG". Not sure if the variation of the name caused the failure. I could change the pn to "21010589*" if that helps. Nope. I tried changing the pn in the text file to "21010589_Primary" and "21010589_Primary.JPG" and ran the script again with the same results.

BTW The file folders in the E: drive are
acdelco-battery-photos (there should be no pictures on the list in this folder)
gm-photos-alternate
gm-primary-2010
gm-primary-2011
gm-primary-2012
gm-primary-2011

Below is the text I put in the notepad and saved as scrip.bat andall filetypes.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

md C:\Users\Francyn\Desktop\ACD Photo Request
SET "DEST_DIR=C:\Users\Francyn\Desktop\ACD Photo Request"
SET "SEARCH_DIR=E:\ gm-primary-2012"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
  FOR /R "%SEARCH_DIR%" %%f IN (*%%a*) DO (
      SET "SRC=%%~dpf"
      SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
      xcopy /S /I "%%~f" "!DEST!"
  )
)


SETLOCAL ENABLEDELAYEDEXPANSION

SET "DEST_DIR=C:\Users\Francyn\Desktop\ACD Photo Request"
SET "SEARCH_DIR=E:\gm-photos-alternate"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
  FOR /R "%SEARCH_DIR%" %%f IN (*%%a*) DO (
      SET "SRC=%%~dpf"
      SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
      xcopy /S /I "%%~f" "!DEST!"
  )
)


SETLOCAL ENABLEDELAYEDEXPANSION

SET "DEST_DIR=C:\Users\Francyn\Desktop\ACD Photo Request"
SET "SEARCH_DIR=E:\gm-primary-2010"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
  FOR /R "%SEARCH_DIR%" %%f IN (*%%a*) DO (
      SET "SRC=%%~dpf"
      SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
      xcopy /S /I "%%~f" "!DEST!"
  )
)

SETLOCAL ENABLEDELAYEDEXPANSION

SET "DEST_DIR=C:\Users\Francyn\Desktop\ACD Photo Request"
SET "SEARCH_DIR=E:\ gm-primary-2011"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
  FOR /R "%SEARCH_DIR%" %%f IN (*%%a*) DO (
      SET "SRC=%%~dpf"
      SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
      xcopy /S /I "%%~f" "!DEST!"
  )
)


Let's try again.  I really appreciate your taking the time to do this.  I opened several folders and a pn search and took a screenshot to help you see what I see.

Francyn

PS - I volunteered as an expert a couple years ago, but it was definitely not in this category. It was Theatre! :)

Answer
Hi there

the MD command didn't like the gaps in "ACD Photo Request"  so i have changed it to ACDPhotoRequest, just to keep things simple.

right then go to the script.bat file you made and right click it and go to "EDIT" select everything and delete it all so its blank again, copy and past in the below and then save file


@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

md C:\Users\Francyn\Desktop\ACDPhotoRequest
SET "DEST_DIR=C:\Users\Francyn\Desktop\ACDPhotoRequest"
SET "SEARCH_DIR=E:\gm-primary-2012"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
 FOR /R "%SEARCH_DIR%" %%f IN (*%%a*.jpg) DO (
     SET "SRC=%%~dpf"
     SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
     xcopy /S /I "%%~f" "!DEST!"
 )
)


SETLOCAL ENABLEDELAYEDEXPANSION

SET "DEST_DIR=C:\Users\Francyn\Desktop\ACDPhotoRequest"
SET "SEARCH_DIR=E:\gm-photos-alternate"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
 FOR /R "%SEARCH_DIR%" %%f IN (*%%a*.jpg) DO (
     SET "SRC=%%~dpf"
     SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
     xcopy /S /I "%%~f" "!DEST!"
 )
)


SETLOCAL ENABLEDELAYEDEXPANSION

SET "DEST_DIR=C:\Users\Francyn\Desktop\ACDPhotoRequest"
SET "SEARCH_DIR=E:\gm-primary-2010"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
 FOR /R "%SEARCH_DIR%" %%f IN (*%%a*.jpg) DO (
     SET "SRC=%%~dpf"
     SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
     xcopy /S /I "%%~f" "!DEST!"
 )
)

SETLOCAL ENABLEDELAYEDEXPANSION

SET "DEST_DIR=C:\Users\Francyn\Desktop\ACDPhotoRequest"
SET "SEARCH_DIR=E:\gm-primary-2011"

FOR /F "tokens=*" %%a IN ('type %~dp0partno.txt') DO (
 FOR /R "%SEARCH_DIR%" %%f IN (*%%a*.jpg) DO (
     SET "SRC=%%~dpf"
     SET DEST=!SRC:%SEARCH_DIR%=%DEST_DIR%!
     xcopy /S /I "%%~f" "!DEST!"
 )
)


Then run the batch file again and then go and look in C:\Users\Francyn\Desktop\ACDPhotoRequest for any results


let me know what happens next ;)

Regards


scott

Windows 7

All Answers


Answers by Expert:


Ask Experts

Volunteer


scott bartholomew

Expertise

General trouble shooting Hardware issues Networking issues I am not a software developer,but I can do some basic scripting in DOS and BASH.

Experience

Worked in IT for over 10 years and currently provide software and hardware support for a very large network of computers, including servers.

Education/Credentials
MCSA CCNA MCP x2 MCTS BTEC

©2016 About.com. All rights reserved.