LuckyLucks
asked on
Find a file in a dir and if found copy it
Hi I want to find a file given its name and if founf want to copy it to another folder , how do I?
find "myfile.pdf"
find "myfile.pdf"
ASKER
sorry windows batch only at the moment
Where do you want to "look" for the file?
If it was just in a particular folder, then you can change to the folder and copy it, like this. But I suspect the file is in a less obvious place?
If it was just in a particular folder, then you can change to the folder and copy it, like this. But I suspect the file is in a less obvious place?
cd c:\somedir
copy myfile.pdf d:\destdir
But if it could be anywhere under a base folder, then you could do something like this, which searches for the file in all subfolders and copys it when found:for /f "tokens=*" %%A in ('dir /b /s /a-d "c:\somedir\myfile.pdf") do copy "%%~A" "d:\destdir"
~bp
ASKER
ok maybe I am not clear......
I have a file called src_file which has lines of filename, like:
myfile1.pdf
myfile2.pdf
I need to iterate thru this list of files and on two specific folders on the server, want to check if they exist there. If they do, I want to copy them to say C:/Found (also on server).
The two folders to search are \\2454-prod\folder1 and \\2454-prod\folder1\subfol der
I have a file called src_file which has lines of filename, like:
myfile1.pdf
myfile2.pdf
I need to iterate thru this list of files and on two specific folders on the server, want to check if they exist there. If they do, I want to copy them to say C:/Found (also on server).
The two folders to search are \\2454-prod\folder1 and \\2454-prod\folder1\subfol
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is there a way to err log the above code into a separate log file?
ASKER
Didnt worl. Pls see attached screen shot of all execution
ErrorDoc.docx
ErrorDoc.docx
I didn't see any errors in that execution screen capture, it just appears that the source file had no records in it.
~bp
~bp
ASKER
The source file does have records and is in the same folder as the batch.
ASKER
Also a sample in the src file is like this:
421ff817e-fdde-471a-b5d1-1 27213d51.p df
24a58ce1-499f-4b36-8225-86 8247ffb.pd f
421ff817e-fdde-471a-b5d1-1
24a58ce1-499f-4b36-8225-86
ASKER
Worked with a few tweaks....the for loop for file was OK. For some reason the dir loop want working....maybe its env related, so I just ran the script twice , once for each of the two dirs.
python is much easier :)
Open in new window