Computing.Net > Forums > Disk Operating System > Rename take out one letter

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Rename take out one letter

Reply to Message Icon

Name: TMLewiss
Date: February 22, 2004 at 16:24:52 Pacific
OS: Windows 2000 SP: 4
CPU/Ram: 1.8 ghz 1.2 gig ram
Comment:

Ok I want to make a batch file that takes a filename and replaces certain characters. EX: Replace all spaces with underscores or replace all A's with Q's



Sponsored Link
Ads by Google

Response Number 1
Name: Wengier
Date: February 22, 2004 at 19:29:55 Pacific
Reply:

http://www.computing.net/dos/wwwboard/forum/14574.html


0

Response Number 2
Name: wt (by think)
Date: February 22, 2004 at 22:57:30 Pacific
Reply:

getting wiser in replying dos batch question, just a single link this time =)


0

Response Number 3
Name: jconner
Date: February 22, 2004 at 23:39:11 Pacific
Reply:

Ok, this is the wrong forum.... But, its a mistake that alot of people make. Its not really clear that Win2k does not use dos. So people get confused.

but.. here you go
First you need a seperate bat file to pass the filenames individually.
Something like...
@echo off

for /r c:\Batfiles\ %%K in (*.jpg) do call c:\rename.bat "%%K"

pause
exit
REM**************************************
Then you have the bat that renames them.


REM**************************************
@ECHO OFF
REM Set the File name without ext to Flenme variable
Set Flenme="%~n1"
REM Set Extn to extension only
Set Extn=%~x1
REM Find Special Characters and Replace them
REM Variable equals variable colon character to replace equals replace with percent
REM Replace Spaces with underscores
Set Flenme=%Flenme: =_%
REM Replace A's with Q's
Set Flenme=%Flenme:A=Q%

REm ADD if statement to end it if the filename has not been changed
REM Should have an acceptable filename so Show it
ECHO %~nx1 Changed to %Flenme%%Extn%
REM ADD If Statement to Rename the file if there is not already a file with that name
REM Now Rename the file
REN "%~f1" %Flenme%%Extn%


Thats it,
you don't have to use a bat to call the other bat. but if you are doing other things, (like copying) this is a good way.
Let me know if it works for you.


0

Response Number 4
Name: jconner
Date: February 22, 2004 at 23:47:30 Pacific
Reply:

by the way...
I put in to set the filename and the ext to seperate variables if you wanted to find a extra"." (periods) you could replace them too. Remove it if you want to rename file extensions as well.


0

Response Number 5
Name: Wengier
Date: February 23, 2004 at 05:10:19 Pacific
Reply:

mit,

"getting wiser in replying dos batch question"

DOS batch is fine in the DOS forum of course. But unfortunately this is not a DOS batch question. Instead, it's a *NT* batch question! For example, I don't think "for /r" will work in DOS.


0

Related Posts

See More



Response Number 6
Name: wt (by think)
Date: February 23, 2004 at 16:53:43 Pacific
Reply:

anyway, you know i'm not talking about dos batch =)


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Rename take out one letter

what!!!!!!!!!!!!!!!! www.computing.net/answers/dos/what/4888.html

Renaming characters in a file name www.computing.net/answers/dos/renaming-characters-in-a-file-name-/11809.html

just in case www.computing.net/answers/dos/just-in-case/4896.html