cmd - Batch script for copying files with folder -


i have list of files path in rarme.txt file. such as:

  • d:\test\bin\test.dll
  • d:\test\bin\test.exe
  • d:\test\image\house\door.bmp
  • d:\beta\apphouse.dll

now how copy files 1 or 2 level folder

for ex: in case of

d:\test\bin\test.dll

how copy test.dll file within bin folder?

and in case of

d:\test\image\house\door.bmp

how copy door.bmp within image\house folder?

this bat script copies file location d:\forpatch , rars it

rem copying files folder pause /f "tokens=*" %%i in (rarme.txt) xcopy "%%i" "d:\forpatch" /s pause cd d:\forpatch pause rar  -ep1 -r patch.rar *.* pause 

hoping understand aim:

@echo off >nul setlocal enableextensions rem copying files folder /f "tokens=*" %%i in (rarme.txt) (   /f "tokens=1,* delims=/\" %%j in ("%%~pi") (     echo if not exist "d:\forpatch\%%~k" mkdir "d:\forpatch\%%~k" 2>nul     echo copy /b "%%~i" "d:\forpatch\%%~k%%~nxi"      ) ) 

note operational mkdir , copy /b commands merely echoed debugging purposes. remove echo no sooner debugged.
output using data:

==>d:\bat\so\31588128.bat if not exist "d:\forpatch\bin\" mkdir "d:\forpatch\bin\" copy /b "d:\test\bin\test.dll" "d:\forpatch\bin\test.dll" if not exist "d:\forpatch\bin\" mkdir "d:\forpatch\bin\" copy /b "d:\test\bin\test.exe" "d:\forpatch\bin\test.exe" if not exist "d:\forpatch\image\house\" mkdir "d:\forpatch\image\house\" copy /b "d:\test\image\house\door.bmp" "d:\forpatch\image\house\door.bmp" if not exist "d:\forpatch\" mkdir "d:\forpatch\" copy /b "d:\beta\apphouse.dll" "d:\forpatch\apphouse.dll" 

then next operational variant of script should work supposing rar command right (not tested not have rar installed).

@echo off >nul setlocal enableextensions rem copying files folder /f "tokens=*" %%i in (rarme.txt) (   /f "tokens=1,* delims=/\" %%j in ("%%~pi") (     if not exist "d:\forpatch\%%~k" mkdir "d:\forpatch\%%~k" 2>nul     copy /b "%%~i" "d:\forpatch\%%~k%%~nxi"      ) ) pushd d:\forpatch pause rar  -ep1 -r patch.rar *.* pause popd  

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -