Batch File to append h_ to each file.

February 25, 2011 at 10:45:50
Specs: Windows XP
I'm desperately trying to append the filenames of a set of images in a folder.
The current filenames are like "myfile123.jpg", and I want to put a "h_" in from so they all become "h_myfile123.jpg"

My latest try with my limited knowledge:
[CODE]rename *.jpg h_*.jpg[/CODE]

This gives my a filename "h_file123.jpg". Looks like it's overwritten the first two characters with the "h_".

Can anyone help?

See More: Batch File to append h_ to each file.

Report •

February 25, 2011 at 13:05:49
The following script that has nothing to do with DOS since XP is NT based

pushd Your_Folder
for %%j in (*.jpg) do ren "%%j" "h_%%~nxj"

Report •

February 25, 2011 at 14:12:43
That's amazing. Thanks for the reply! and the kind help so far.
My days of scripting were mainly DOS based. This is new to me.

If I wanted to append the "_h" to the end of the file and create something like:
"myfile123_h.jpg", what changes would I make to the above?


Report •

February 26, 2011 at 06:56:49
pushd Your_Folder
for %%j in (*.jpg) do ren "%%j" "%%~nj_h%%~xj"

Report •

Related Solutions

February 26, 2011 at 10:44:54
IVO. You seem to be the batch file king!
Of course it works, thing is I don't totally understand this...
Are there any good books / sites that I could learn from?

Thanks again

Report •

February 26, 2011 at 13:06:25
NT batch is more powerful than its partially compatible DOS ancestor. New switches and statements' structures now are available as the ~ internal variable modifier, but this is just the peak of the iceberg.

I can't suggest you a good book as I learned what I know by starting from a good knowledge of plain DOS batch and reading the (not always friendly) on-line help you get typing thr /? switch after the command code. If you type for /? you get the answers to understand the meaning of my post. Following that lane don't miss to query about statements you believe to know well since surprises may come. To get the full list of available commands type help | more.

Report •

Ask Question