Computing.Net > Forums > Windows XP > XP Batch Files - Renaming

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

XP Batch Files - Renaming

Reply to Message Icon

Original Message
Name: gabson
Date: October 29, 2006 at 16:16:42 Pacific
Subject: XP Batch Files - Renaming
OS: XP Pro SP2
CPU/Ram: Intel P4 2.4 GHZ 512MB
Comment:

I am trying to write a batch file that will rename a series of files within a folder. I need it to remove the first 8 characters, then add its own prefix and suffix. I don't have much experience with writing complex batch files, but here is what I've got and all it does is rename it to "prefixsuffix" with no extension. Can anyone help me out? Am I on the right track or is this even possible with this method?

for %%R in (*.*) do (
SET NAME=%%R:~8,-4%
SET EXT=%%R:~-4%
REN %%R prefix%NAME%suffix%EXT%
)

Thanks in advance!


Report Offensive Message For Removal


Response Number 1
Name: mattie
Date: October 29, 2006 at 16:56:21 Pacific
Reply: (edit)

belongs into the 'programming' section.

Today's subliminal thought is: 'Calm down ... it's only ones and zeros.'

icq 10183575


Report Offensive Follow Up For Removal

Response Number 2
Name: Mechanix2Go
Date: October 29, 2006 at 21:09:57 Pacific
Reply: (edit)

@echo off
setLocal EnableDelayedExpansion

for %%R in (*.*) do (
SET NAME=%%~nR
echo REN "%%R" "prefix!NAME:~8,99!.suffix"
)



=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home








Do you own an iPhone?

Yes
No, but soon
No


View Results

Poll Finishes In 7 Days.
Discuss in The Lounge
Poll History




Data Recovery Software