Search Find Copy File - Scripting

December 18, 2010 at 15:16:42
Specs: Windows xp
I have an application that will generate file in Folder A, I need to check that file in Folder B and copy file in folder B to Folder C

how to write a script ?

See More: Search Find Copy File - Scripting

Report •

December 19, 2010 at 14:57:42
I'm ASSuming when you say "check that file in folder B", you mean "does it exist".
(another possibility is a comparison of the file's content. but i'll got with the ASS first, Lol!)
copy /y folderB\filename folderC\filename 2>nul

which will copy (or move, if you prefer, using "move" instead of "copy") the file
if it is there, and if it's not, nothing happens and the errormsg should be supressed.

Report •

December 19, 2010 at 16:14:12
Hi tks for the reply.
My case is different.

Application will generate file in FolderA,
FolderB got about 5000 files. I need to search the file name (in FolderB) witch is generated in FolderA and matched n copy file ( in folderB) to FolderC

get file name from FolderA

Search file name in FolderB

Copy matched file in FolderB to FolderC

Report •

December 19, 2010 at 16:36:30
oh, maybe like this, assuming there's only one .dfg file in folder "A":
@echo off & setlocal
for %%a in (folderA\*.dfg) do (
copy /y folderB\%%~nxa folderC
'---- end
if there's more than one, you need a way to figure out which one you want
(newest, oldest, biggest, etc.)

Report •

Related Solutions

December 19, 2010 at 17:36:55
Appreciate your reply,

saved as test.cmd when I run it says " system cannot find the file specified "

FolderA file extension (dfg) is different than FolderB file extension (def)

Any idea

Report •

December 19, 2010 at 20:57:50
Hi Nbrane,

I got it working. Thank you very much.

code as follows
for %%a in (folderA\*.dfg) do (
copy /y folderB\%%~na folderC

Report •

December 19, 2010 at 21:21:04
correct one....

for %%a in (folderA\*.dfg) do (
copy /y folderB\%%~na.def folderC

Report •

Ask Question