FOR ever

Feb 23, 2010 17:30

Windohs actually has smartened up a bit over the years, I just found that their "dos" batch version of the for loop _does_ support subparameters (figures i just learned that typing for /help gives you this command syntax listing)

So if for example you wanted to rename a bunch of .jpeg files to plain old .jpg

You're able to run the loop using variable for the filename, but I just learned you can excise just the trunk file name or extension -- or just copy n paste my line below:

for %i in (*.jpeg) do rename %i %~ni.jpg

Note the little tilde-n there (no it's not a spanish typo lol)



Just snipped out ones I might actually use, namely, current filename info

%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file

The modifiers can be combined to get compound results:

%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~ftzaI - expands %I to a DIR like output line

Of course I've been doing this on MacOSX for years, just never thought windohs had it too.

This could be used for .htm/.html renaming also, or pretty much whatever you like. Next stop's to make a loop that would rename a bunch of files to fit some numeric convention, eg. image1.jpg, image2.jpg,... or other similar.. loopy.. constructs

sup, werd, geek

Previous post Next post
Up