1.

Solve : Renaming a bunch of files to remove a "Q" from the name?

Answer»

Hello all.

I have been unable to figure this simple ONE out. I have been out of writing DOS scripts for a while now and am a little rusty.

I have a folder full of files that contain a Q in them and I want to remove the Q.

ie.  sf0000q.ps s/b renamed to sf0000.ps

Rename with a wild card doesn't work and I am stumped.
Any help would be appreciated.

KenThis is not a class assignment?

You can use Excel or some other spreadsheet to Crete a batch file that does that. Is it considered unfair to use another program?

I would recommend SED, but it is not included on Windows systems.

Also, what it there are already other files the would have the same name if it were not for the Q. Who put in the Q and why?

My point is that programming is not about getting some code. It is more about what you are doing. Just removing the Q from a group of files is not so hard. What is hard is the con sequences.What are you talking about a class assignment?

I have an automatic export process from an HP3000 that will send down files every day and I need to rename the files so that I can process them and load them into my Oracle database.

I have been programming in a 4gl language since 1986 and do not use DOS that often.

As for SED, I prefer VI, or VIM to do any editing. Not to mention this is an MS DOS forum, not a UNIX forum.
Don't mind ol' Geek, he's just TRYING to be helpful. If you have been programming in a 4GL language for NEARLY 30 years then you should find Windows command language a breeze. And you would know that SED (and awk for that matter) exist in Windows ports, and that SED is not an "editor" in the same way that VI and VIM are. What OS were you using back in 1986?



KenL, OK.Got it.
If you have a solution in UNIX you can likely use it in most current Windows system as a command to one of the UNIX utilities that have been ported to Windows.
The following is not an endorsement by Microsoft, but as close as you can get:
http://technet.microsoft.com/en-us/library/bb463168.aspx
But the link below is easier to read for me:
http://en.wikipedia.org/wiki/UnxUtils Code: [Select]echo off
setlocal enabledelayedexpansion
for /f "delims=" %%A in ( 'dir /b *.ps' ) do (
set oldname=%%~nA
set newname=!oldname:q=!
ren "!oldname!%%~xA" "!newname!%%~xA"
)

Thank You Salmon Trout?

EXACTLY what I was looking for.


Just a question, what does the SETLOCAL ENABLEDELAYEDEXPANSION do? Quote from: KenL on February 09, 2012, 12:18:15 PM

SETLOCAL ENABLEDELAYEDEXPANSION do?

NORMALLY a batch script is run in 2 phases (1) parse (2) run. At parse time all the variables are expanded. In a FOR loop it would not be possible to assign values to and read values from such variables. Delayed expansion allows expansion of variables at run time. Such variables use ! as the variable name delimiter. This topic is very heavily covered at many web locations, so you will forgive me for not writing an article about it for you.

ok, thanks again for your help.


Discussion

No Comment Found