Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.



Windows 7: search multiple files, copy+paste to new folder (batch file software?)

03 May 2012   #1

Windows 7 32 bit
 
 
search multiple files, copy+paste to new folder (batch file software?)

I am a complete newbie when it comes to batch files and batch file software, so apologies in advance.

I've done some research on Google etc but I seem to just be getting more and more confused trying to use various different scripts and programs and reading different info on various websites.

This is what I need...

I have a folder with around 2000 files in it. I want to be able to copy certain files from this folder (normally around 40) and place them in a brand new folder, I want to be able to do this with nothing more than a txt file that has all the file names I need copying in it with every file name on a separate line.

I receive around 10 new txt files each day so you can imagine how tedious it is searching through 2000 files, picking out the 40 I need, 10 times a day everyday.

To make things even more complicated, the txt files I receive don't always have the correct file names in them, maybe there's a misspelling or a word or two missing for some of the names. That's ok when I'm going through picking out the files I need to copy myself because I can normally tell which file is being requested, but I can't see it being so easy for a program or whatever to do, I'm guessing it'll need to have a search feature where it picks out the most likely file.

I'd like it to be as automated as possible. I receive the txt file, make sure each file name is on a separate line then a program or script or whatever goes out and picks out the files (or most likely files for the name's that aren't exact matches) and copies them into a brand new folder (which I'd like to be the same name as the text file it's using to choose the files).

I hope this makes sense, I've probably made it sound a lot more complicated than I needed to, I've been looking for a solution for weeks now so my brains gone a bit foggy :/

I'd appreciate any help you can offer!

My System SpecsSystem Spec
.

03 May 2012   #2

Windows 7 x64
 
 

Contact Rent-A-Coder, Elance, or any of the other programming for hire sites. They could knock this out pretty quickly I would think.
My System SpecsSystem Spec
04 May 2012   #3

Windows 7 Ultimate x64
 
 

Code:
@echo off
rem Text file with filenames
rem To be prompted for this change to  'set /p LIST=Path to text file: '
rem Or 'set LIST=%1' to run from cmd line like, filename.bat "D:\List.txt"
set LIST="D:\List.txt"

rem Path to the files to copy
rem Can be change the same as LIST
rem Or 'set FILESPATH=%2' to run like , filename.bat "D:\List.txt" "D:\Test"
set FILESPATH="D:\Test"

rem Destination path can be added here. eg set DESTPATH=C:\New Folder
rem If set change xcopy cmd to "%DESTPATH%\%DEST%\*"
rem Do not use quotes when setting DESTPATH

rem Set Destination folder based on LIST name
for %%i in (%LIST%) do set DEST=%%~ni

rem Read LIST and call :COPY_FILES for each line passing the line of text
for /F "usebackq delims==" %%i in (%LIST%) do (call :COPY_FILES "%%i")

exit

:COPY_FILES
rem Destination folder created in same location the batch file is run from
xcopy /qv %FILESPATH%\%1 .\%DEST%\*
This is a simple batch file that will do the first part but for the incorrect filenames thats a lot harder.

There's only two options that I think will work with this script and that's to create a text file of any files that are not found (incorrect names) then manually copy them or using substrings with wildcards which probably won't work very well.

You might have better luck asking on a scripting forum but I don't think so. The problem I see is to find possible matches you need to break the string up and find files that contain the broken up parts of the string and use wildcards.

For example you had the file listed as "Seven orums" and you had the files
Seven Dwarfs
The Last Seven
Instruments
Seven Forums

Now if you search for Seven* (* = any char) then it would return Seven Dwarfs and Seven Forums. If you search for *orums, it would return Seven Forums.

But how do we break it up,
*rum* = Instruments
Sev* = Seven Dwarfs, Seven Forums
*Sev* = Seven Dwarfs, The Last Seven, Seven Forums
ven* = Nothing
*en oru* = Nothing

To many possibilties and out of 2000 files how many would be returned with partital matches?

I don't know if there would be any 3rd party software that could do this either.
My System SpecsSystem Spec
.


04 May 2012   #4

Windows 7 Ultimate x64
 
 

Improved code for multiple List files in one folder. I left the old code there because the comments are still valid except the destination path is included in this one.
Code:
@echo off

set LISTFOLDER=D:\List Files
set FILESPATH=D:\Test
set DESTPATH=D:\New Folder

for /f "tokens=*" %%i in ('dir /b ^"%LISTFOLDER%\*.txt^"') do (call :COPY_FILES "%LISTFOLDER%\%%i")

pause
exit

:COPY_FILES
for %%i in (%1) do set DEST=%%~ni
for /f "usebackq delims==" %%i in (%1) do xcopy /qv "%FILESPATH%\%%i" "%DESTPATH%\%DEST%\*"
My System SpecsSystem Spec
18 Oct 2012   #5

windows 7 home premium 32 bit
 
 

To revive this thread, i also have this need. Ie, folders with thousands of file names to search through in the hope of copying 20 of them into a new folder. Unlike Insatiable 11, my file names are reliably correct.

My journey of understanding batch scripts began this morning.
Can anyone recommend a thread/tutorial, which can help me interpret Duzzy's posts, so I can create a working batch file using his recommended formulas?

cheers all..
My System SpecsSystem Spec
20 Oct 2012   #6

windows 7 home premium 32 bit
 
 

anyone?
My System SpecsSystem Spec
Reply

 search multiple files, copy+paste to new folder (batch file software?)





Thread Tools



Similar help and support threads for2: search multiple files, copy+paste to new folder (batch file software?)
Thread Forum
select/search multiple files, copy and paste to a new folder General Discussion
Batch file to copy files from C drive to USB Backup and Restore
Custom batch file that copies font files to another folder? General Discussion
Need a Batch File to Copy to a Custom Dest Folder Network & Sharing
Solved a simple batch file for copy files and folders General Discussion
Batch file or Exe to copy & rename directory and update files General Discussion
Batch file for moving files to folder? General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 05:49 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33