Hi,
I'm looking for a solution for the problem how can I rename a list of files?
For example: ren Table_23454423.txt 2345423.txt. This works for one file. But I have a list of files like Table_XXXXX.txt and all should be renamed in XXXXX.txt.
I assume I need the command 'For' for it. But I don't know how I can use it. Is anybody there which can solve this problem?
[solved] Rename list of files
Moderator: DosItHelp
didley,
Try this:
Create a batch file, i.e. myrename.bat
put the following code in it:
The %%f:~6%% will cut off the first 6 characters.
For testing you can temporary replace the the 'ren' command with 'echo'.
Or from a command line run this:
Now !f:~6! will cut off the first 6 characters.
Again for testing you can temporary replace the the 'ren' command with 'echo'.
DOS IT HELP ?
Try this:
Create a batch file, i.e. myrename.bat
put the following code in it:
Code: Select all
@ECHO OFF
for %%a in (*.txt) do @set f=%%a&call ren "%%a" "%%f:~6%%"
The %%f:~6%% will cut off the first 6 characters.
For testing you can temporary replace the the 'ren' command with 'echo'.
Or from a command line run this:
Code: Select all
cmd /v:on /c "for %a in (*.txt) do @set f=%a&ren %a !f:~6!"
Now !f:~6! will cut off the first 6 characters.
Again for testing you can temporary replace the the 'ren' command with 'echo'.
DOS IT HELP ?
kaputko,
Sure, here is one way this can be done:
Here another one:
works too because:
"!f:~15,3!" - extracts 3 characters beginning at position 15 (start couting at 0)
"!f:~21!" - extracts all characters after position 21 (start counting at 0)
DOS IT HELP?
Sure, here is one way this can be done:
Code: Select all
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
for %%a in (*.txt) do (
set "f=%%a"
set "f=!f:random numbers_=!"&REM REMOVES "random numbers_"
set "f=!f:_-_= !"&REM REPLACES "_-_" WITH A SINGLE SPACE
ren "%%a" "!f!"
)
Here another one:
Code: Select all
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
for %%a in (*.txt) do (
set "f=%%a"
ren "%%a" "!f:~15,3! !f:~21!"
)
works too because:
"!f:~15,3!" - extracts 3 characters beginning at position 15 (start couting at 0)
"!f:~21!" - extracts all characters after position 21 (start counting at 0)
DOS IT HELP?