I want to find specific files (*quiz*.htm or *.log) from all subdirectories and copy them to a folder, all files should have sepearter name (1.htm,2.htm,3.htm,4.htm.....)
how can i do this?
i used this first
c:\>xcopy *quiz*.htm d:\myfolder /e
but it copies all empty folders then i am trying this but it is still very difficult
for /r c:\ %%s in (*.log) do (for /L %%t in (1 1 1000) do xcopy "%%~dps%%~nxs" D:\quizes\%%t.log)
there could be many files with same name thats why i want to copy them with different names
Need help
Find specific files from a directory and copy to a newfolder
Moderator: DosItHelp
Re: Find specific files from a directory and copy to a newfolder
lifeh2o
Try if this will work for you.
Regards
aGerman
Try if this will work for you.
Code: Select all
@echo off &setlocal
set /a n=0
set /a m=0
for /f "delims=" %%a in ('dir /a-d /b /s "c:\*.log" "c:\*quiz*.htm"') do call :sub "%%a"
goto :eof
:sub
if /i "%~x1"==".log" (
set /a n+=1
call set i=%%n%%
) else (
set /a m+=1
call set i=%%m%%
)
copy %1 "D:\quizes\%i%%~x1"
goto :eof
Regards
aGerman
Re: Find specific files from a directory and copy to a newfolder
Thank you very much
After a lot of tries i made work this simplified code
SetLocal EnableDelayedExpansion
for /r c:\ %%s in (*quiz*.htm) do (
set /a v+=1
copy "%%~dps%%~nxs" D:\quizes\!v!.htm)
You have done this for both files, i am still very curuious about batch files, they help a lot in tedious tasks.
Thanks again, I will learn a lot about batch files in this forum.
After a lot of tries i made work this simplified code
SetLocal EnableDelayedExpansion
for /r c:\ %%s in (*quiz*.htm) do (
set /a v+=1
copy "%%~dps%%~nxs" D:\quizes\!v!.htm)
You have done this for both files, i am still very curuious about batch files, they help a lot in tedious tasks.
Thanks again, I will learn a lot about batch files in this forum.