Need comments on my first ever DOS script program

Saturday, May 3, 2014

Took me about 2 hours to write some DOS code :)


I want to rename all jpg images to the same name as the parent directory (with a number added at the end)


I wanted comments on my code and whether it is optimal without any bugs?


This is what I have:



setlocal EnableDelayedExpansion

REM Get just the name of parent directory - and not the full path
FOR /D %%I IN ("%CD%") DO SET _LAST_SEGMENT_=%%~nxI

set /a i=1

for /f "delims=" %%a in (' dir *.jpg /b /a-d ') do (

ren "%%a" "%_LAST_SEGMENT_% !i!.jpg"
set /a i=i+1
)

Pause


echo off has been intentionally left off - I'll add when finished.


Pause has been added for now, finished version won't have.


Thanks!







http://ift.tt/1i79inL