Computing.Net > Forums > Programming > filename character removal batch

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.

filename character removal batch

Reply to Message Icon

Name: flateric
Date: December 27, 2008 at 14:46:06 Pacific
OS: Windows XP
CPU/Ram: 3000mhz 1gb
Product: Dell / 9150
Comment:

what command can i use to remove the first 15 chars of hundereds of files so i can get them in alphabetical order, files are named CBEP???-?-?? - filename.xxx, the ? are different for every file (numbers) i want to remove everything apart from filename.xxx. cheers, Royce



Sponsored Link
Ads by Google

Response Number 1
Name: reno
Date: December 28, 2008 at 02:31:09 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

set okToRename=n
:loop
for /f "tokens=* delims= " %%f in ('dir /b /a-d CBEP*.*') do (
set filename=%%f
if !okToRename!==y (ren %%f !filename:~15!) else (echo %%f==^>!filename:~15!)
)
set /P okToRename="Is It OK to Rename Those File(s) (y/n)?"
if !okToRename!==y goto :loop


0

Response Number 2
Name: A2Z
Date: December 28, 2008 at 12:55:10 Pacific
Reply:

The original post seems to include spaces in the 13th and 15th positions in the filenames, and spaces may be present in the path to the files. Would it not be wise to enclose the path/filenames in " "?


0

Response Number 3
Name: Mechanix2Go
Date: December 29, 2008 at 05:07:14 Pacific
Reply:

@echo off & setLocal EnableDelayedExpansion

pushd c:\files

for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
set FN=%%a
set FN=!FN:~15,77!
ren "%%a" "!FN!"
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: reno
Date: December 29, 2008 at 05:56:18 Pacific
Reply:

dang, didnt thought of the space. hope i havent cause any damage in the renaming process.

those batch scripting is still new stuff to me, i will be more careful in the future.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: filename character removal batch

Using the arrow character in batch. www.computing.net/answers/programming/using-the-arrow-character-in-batch/18976.html

Removing Special Characters FOR Loop www.computing.net/answers/programming/removing-special-characters-for-loop/18895.html

Special characters in batch www.computing.net/answers/programming/special-characters-in-batch/19558.html