Solved I need you help me

Dell /
December 5, 2012 at 15:45:18
Specs: windows 7 service pack 2, pentium 4 2 gb
I have the following file name:
aaaammddhhmm(WW)12345678.txt
I would like to execute a batch file to rename all the files in the directory removing the text between the ( ).
Please provide a brief description of what your solution does to fix my problem.

See More: I need you help me

Report •


✔ Best Answer
December 6, 2012 at 17:09:17
Ah, yes, a whole different ball-game is afoot. I was carrying a bat, wearing my cleats, and you're playing hockey. ;-)
Ok, let me try another shot, with my ice-skates and hockey-stick this time:
::begin batchscript
for %%a in (*.txt) do call :rename "%%~na"
goto :eof
:rename
set x=%~1
echo ren "%~1.txt" "%x:~0,12%%x:~14%.txt"
:: end batchscript

ASSumed: all .txt files in working directory qualify for renaming.
Batch is written to be run from same dir. as the .txt files, other wise insert path B.S as needed.
Batch is "safety-ed": it will not rename the files until you remove the "echo" from last line of script. It will display what it intends to do to your filenames.



#1
December 5, 2012 at 16:58:06
As long as there's not more than one set of () in any filename, this might work:
for /f "tokens=1-2* delims=()" %%a in ('dir /b *.txt') do echo ren %%a(%%b)%%c %%a()%%c

Report •

#2
December 6, 2012 at 02:23:55
Hello Nbrane
Three things

1, When I say beteween ( ) the () are not included on the name, I put () only to signal the positiot, in fact the name is
aaaammddhhmmWW12345678.txt

2. Doesn't work. I have copied nad paste in the change. bat file.
It doesn't change nothing.
for /f "tokens=1-2* delims=()" %%a in ('dir /b *.txt') do echo ren %%a(%%b)%%c %%a()%%c

3. What will happend if after two digits that I want delete the name have more digits than appear on this example?

Thank you for your help


Report •

#3
December 6, 2012 at 05:49:24
Dracir: When I say beteween ( ) the () are not included on the name / Doesn't work.
You see? This is why you tell us the truth up front. We can't see your monitor. We have to go by what you tell us. Is there anything else you want to come clean about?

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
December 6, 2012 at 06:49:20
Ok, maybe my exposition was not clear.
I need delete 2 digits after 12 digits
original-> aaaammddhhmmXX12345671.txt
original-> aaaammddhhmmRR12345672.txt
final -----> aaaammddhhmm12345671.txt (XX removed)
final -----> aaaammddhhmm12345672.txt (RR removed)
This procedure with all file from folder when I execute the bat.

I hope now is clean


Report •

#5
December 6, 2012 at 17:09:17
✔ Best Answer
Ah, yes, a whole different ball-game is afoot. I was carrying a bat, wearing my cleats, and you're playing hockey. ;-)
Ok, let me try another shot, with my ice-skates and hockey-stick this time:
::begin batchscript
for %%a in (*.txt) do call :rename "%%~na"
goto :eof
:rename
set x=%~1
echo ren "%~1.txt" "%x:~0,12%%x:~14%.txt"
:: end batchscript

ASSumed: all .txt files in working directory qualify for renaming.
Batch is written to be run from same dir. as the .txt files, other wise insert path B.S as needed.
Batch is "safety-ed": it will not rename the files until you remove the "echo" from last line of script. It will display what it intends to do to your filenames.


Report •


Ask Question