|
Answer» Good afternoon,
I have a bunch of files that I would like to rename. I NEED to change all of them to delete A60- from the beginning of the file name but keep everything else.
EXAMPLE: A60-1000-0051_P14_J.pdf rename to 1000-0051_P14_J.pdf A60-1000-0051_P14_K.pdf rename to 1000-0051_P14_K.pdf A60-1000-0052_P1_B.pdf rename to 1000-0052_P1_B.pdf
The code i got so far to work is: rename "A06-*.*" "1000*.*"
The only bad thing is that I have an extra 1000 in the file name. Example: A60-1000-0051_P14_J.pdf after running the code 10001000-0051_P14_J.pdf
Does ANYBODY know how I can get rid of the extra 1000 in the file name?
I FIGURE out that if I put spaces in the " 1000*.*" code that it got rid of the extra 1000, but now my file names has 4 spaces in front of it.
Thanks in advance. Son NguyenYou can use a FOR /F loop.
In your first example, where you want to remove the A60- from the front of all the files, you can do: Code: [Select]@echo off setlocal enabledelayedexpansion for /f %%a in ('dir a60* /b') do set file=%%a&ren %%a !file:~4!
To fix the extra "1000" on the front, you can use almost the same code: Code: [Select]@echo off setlocal enabledelayedexpansion for /f %%a in ('dir 10001000* /b') do set file=%%a&ren %%a !file:~4!
Or if you want code that will strip off the first 4 characters from the file name no matter what it is (be careful with this), you can use this code for both scenarios: Code: [Select]@echo off setlocal enabledelayedexpansion for /f %%a in ('dir /b') do set file=%%a&ren %%a !file:~4! Thanks the help. Got the code to work. You're welcome
|