Search file and copy in other disk, but directory structure
Moderator: DosItHelp
Search file and copy in other disk, but directory structure
Hello Everybody,
I have new question for you expert.
My goal is search (for) a file in a disk (C) from list.txt and copy to other disk (D) in the same place (directory)
Example:
Original file:
C:\dir1\letter1.txt
C:\letter2.txt
C:\dir3\dir2\letter3.txt
file list.txt contain
letter1.txt
letter2.txt
letter3.txt
Result for new file:
D:\dir1\letter1.txt
D:\letter2.txt
D:\dir3\dir2\letter3.txt
Regards
Dario
I have new question for you expert.
My goal is search (for) a file in a disk (C) from list.txt and copy to other disk (D) in the same place (directory)
Example:
Original file:
C:\dir1\letter1.txt
C:\letter2.txt
C:\dir3\dir2\letter3.txt
file list.txt contain
letter1.txt
letter2.txt
letter3.txt
Result for new file:
D:\dir1\letter1.txt
D:\letter2.txt
D:\dir3\dir2\letter3.txt
Regards
Dario
Re: Search file and copy in other disk, but directory struct
Searching over the entire hard drive wastes a lot of time. I would like to know how long your list is. If it is not too long the DIR command could handle all on the fly. Otherwise we have to call the FINDSTR command for each file on your hard drive. That needs approx. 200ms additional time per file
Please give a short information.
Please give a short information.
Re: Search file and copy in other disk, but directory struct
The number of item to search are 181 items on total of 300 items. (but starting all from specific folder like C:\PDF\)
Regards
Dario
Regards
Dario
Re: Search file and copy in other disk, but directory struct
Code: Select all
@echo off
set "src=c:\pdf\"
set "list=c:\list.txt"
set "dest=d:\"
for /f "delims=" %%f in (
'dir /a-d/b/s "%src%" ^|findstr /eig:"%list%"'
) do echo f|xcopy "%%f" "%dest%%%~pnxf"
Re: Search file and copy in other disk, but directory struct
Well, !k, I had the same idea to use the /g option. But then I noticed that it would not work right. If there is a file abc.txt in the list but you have a file yxzabc.txt into the search environment then it will be copied as well.
@Dario
Take care that there are no spaces behind the file names in your list.
Regards
aGerman
Code: Select all
@echo off &setlocal
for /f "tokens=* delims=" %%a in ('dir /a-d /b /s "C:\PDF\"') do (
findstr /ixc:"%%~nxa" "list.txt" >nul &&(
xcopy "%%~a" "D:%%~pa" /iqy
)
)
@Dario
Take care that there are no spaces behind the file names in your list.
Regards
aGerman
Re: Search file and copy in other disk, but directory struct
!k wrote:Code: Select all
@echo off
set "src=c:\pdf\"
set "list=c:\list.txt"
set "dest=d:\"
for /f "delims=" %%f in (
'dir /a-d/b/s "%src%" ^|findstr /eig:"%list%"'
) do echo f|xcopy "%%f" "%dest%%%~pnxf"
Many Thanks, this one works really file also with space in name file 424/425 file copied (now I check the missing one)
Re: Search file and copy in other disk, but directory struct
Maybe file not missing but superfluous? Look to aGerman's post
example list.txt
My batch will copy both "need.txt" and "NOT_need.txt" files
And
example list.txt
Code: Select all
need.txt
And
Take care that there are no spaces behind the file names in your list.
Last edited by !k on 08 Mar 2011 07:55, edited 1 time in total.
Re: Search file and copy in other disk, but directory struct
aGerman wrote:Well, !k, I had the same idea to use the /g option. But then I noticed that it would not work right. If there is a file abc.txt in the list but you have a file yxzabc.txt into the search environment then it will be copied as well.Code: Select all
@echo off &setlocal
for /f "tokens=* delims=" %%a in ('dir /a-d /b /s "C:\PDF\"') do (
findstr /ixc:"%%~nxa" "list.txt" >nul &&(
xcopy "%%~a" "D:%%~pa" /iqy
)
)
@Dario
Take care that there are no spaces behind the file names in your list.
Regards
aGerman
Same result, this one works file "but slower" also with space in name file 424/425 file copied (now I check the missing one)
Regards
Dario
Re: Search file and copy in other disk, but directory struct
I try to improve a little this script, setting on top a search like "DIR /S *.PDF > list.txt but a list is comprensive of path, and the copy script doesn't work.
I can fix this problem?
Regards
Dario
I can fix this problem?
Regards
Dario
Re: Search file and copy in other disk, but directory struct
Hmm, don't get it. Does it mean that you want to redirect the file names without path?
But then the XCOPY code will find exactly the same files again
Regards
aGerman
Code: Select all
>list.txt type nul
for /f "tokens=* delims=" %%a in ('dir /a-d /b /s *.pdf') do >>list.txt echo %%~nxa
But then the XCOPY code will find exactly the same files again
Regards
aGerman