Computing.Net > Forums > Programming > Batch to search and copy to new Dir

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch to search and copy to new Dir

Reply to Message Icon

Name: Cameronh
Date: August 8, 2008 at 08:59:42 Pacific
OS: XP pro
CPU/Ram: core duo/2gb
Comment:

I am looking for a batch file that will search a specified folder for files with a specific name, then copy the found files to a new directory.
Basically I have a folder with 100,000 plus documents for all customers and I need to select the files that are for one specific customer from this list and send them the files. So I would like a batch file that can search this folder for files with certain names and copy them to a new folder so I can send just the folder with the files that are for that customer without having to manually search and copy all their specific files.

Any help would be appreciated

Thanks,
Cam



Sponsored Link
Ads by Google

Response Number 1
Name: Hans Henrik
Date: August 8, 2008 at 09:19:13 Pacific
Reply:

here goes...

@echo off
cls
:sets
echo you can say "DefaultSearch" for default folder
echo DONT use ""
set /P SearchIn=what folder shal i search in?:
cls
set DefaultSearch=C:\DefaultSearch\
set /P FileToSearch=what files to search'n copy?:
cls
echo you can say Default for the default folder
echo DONT use ""
set /P CopyTo=where shal i copy to?:
set Default="C:\default folder"
:begin
cd "%SearchIn%"
copy *FileToSearch* "%CopyTo%"
if not %ErrorLevel% == 0 echo some error, errorlevel is %ErrorLevel% & pause
:end
echo um... all done
pause
exit


i could make a log-system 2 if you would want that.. :p


0

Response Number 2
Name: Cameronh
Date: August 8, 2008 at 09:46:11 Pacific
Reply:

This appears to almost work, with the acception of it only being able to search one file name and once it copys the file it renames it filetosearch.

I need the file names to stay the same, and I need to be able to search for multiple files at a time.
E.g need to search for File2, file25 and file1003, then copy them to the new directory with the same name.

Sorry I guess I should have been more clear.


0

Response Number 3
Name: Mechanix2Go
Date: August 8, 2008 at 10:04:14 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

if %1'==' echo which files? && goto :eof
pushd c:\src

for /f "tokens=* delims= " %%a in ('dir/b %1') do (
copy %%a d:\dest
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: Cameronh
Date: August 8, 2008 at 10:59:47 Pacific
Reply:

Hello M2,

Not sure how that batch is suppose to work, can you please explain to me how this one you listed works?
Do I add this to the original one?


0

Response Number 5
Name: Mechanix2Go
Date: August 8, 2008 at 12:04:58 Pacific
Reply:

"Do I add this to the original one?"

No; use it by itself. On the command line, give a filespec, like:

*.XLS


=====================================
If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: ghostdog
Date: August 8, 2008 at 18:25:20 Pacific
Reply:

doesn't

 copy *.xls destination 
do it?

0

Response Number 7
Name: BatchFreak
Date: November 1, 2008 at 08:55:05 Pacific
Reply:

Only if the persons files are all *.xls and noone elses.

I only Batch if possible, 2000 more lines of code, oh well.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch to search and copy to new Dir

Batch File Search and Paste www.computing.net/answers/programming/batch-file-search-and-paste-/15699.html

Search a local file and copy to a share www.computing.net/answers/programming/search-a-local-file-and-copy-to-a-share/19967.html

Batch File search and delete file www.computing.net/answers/programming/batch-file-search-and-delete-file/16386.html