Skip to content

Instantly share code, notes, and snippets.

@ricardoparro
Created September 26, 2013 21:46
Show Gist options
  • Save ricardoparro/6721056 to your computer and use it in GitHub Desktop.
Save ricardoparro/6721056 to your computer and use it in GitHub Desktop.
file manipulator - windows batch script
@echo on
setlocal enabledelayedexpansion
rem this first iteration grabs all ok files and copy them to the destination
for /F %%i in ('dir C:\robocopyTest\source /s /b') do (
Set originalFileName=%%~ni
Set prefix=!originalFileName:~0,3!
if !prefix! == OK_ (
XCOPY "%%i" C:\robocopyTest\destination /Y
)
)
rem this grabs all ok files on destination and change the name of all files
for /F %%f in ('dir C:\robocopyTest\destination /s /b') do (
set oldname= %%~nf
set newname=!oldname:~4!
ren "%%f" "!newname!.pdf"
)
for /F "tokens=*" %%b in ('dir C:\robocopyTest\source /s /b') do (
Set originalSourceFileName=%%~nb
Set exists = "false"
for /F %%g in ('dir C:\robocopyTest\destination /s /b') do (
Set destinationSourceFileName=%%~ng
pause
if !destinationSourceFileName! == !originalSourceFileName! (
pause
Set exists ="true"
)
)
if !exists! == "false" (
XCOPY "%%b" C:\robocopyTest\destination /Y
)
)
pause
::FOR /F "tokens=*" %%i in ('dir C:\Projects /AD /s /b') DO (
::echo "%%i"
::REM XCOPY "%%i\*.jpg" C:\robocopyTest /Y
::)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment