Computing.Net > Forums > Disk Operating System > Remove chacters from file names

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.

Remove chacters from file names

Reply to Message Icon

Name: hoopsbwc34
Date: October 6, 2003 at 16:31:06 Pacific
OS: Win XP
CPU/Ram: 2.4GHz,512MB
Comment:

I search for this solution as I see there are many different dos renaming threads, but I couldn't find one to do this specifically.

I want to remove 3 characters from a filename very time they occur. The characters are "10M" and they can occur anywhere (except in the first 3 characters of the filename). Some of these filenames are long names too, so I'm not sure if I can do this in dos or not, but this was my first shot.

Thanks.




Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: October 7, 2003 at 02:17:06 Pacific
Reply:

The batch you find below satisfies your need, but it runs in a DOS box under Windows NT/2K/XP only, it does not work under Win 9X/ME.

It renames the files stored in the directory typed on the command line according to your specifications (excluding those beginning with 10M). Filenames may be long format and contain blank characters. Folder name must not contain blanks.

To run type XStr Folder_Name
or if you want process in the current directory just type XStr . (XStr "dot")

To activate erase the Echo in front of thr Ren command at the bottom of code. Do this only when you are sure the script works as you planned.

@Echo Off

Set FDir=%~f1
For /F "tokens=* delims=" %%I in ('Dir %FDir% /B /A:-D') Do Call :SUBST %%I
GoTo :EOF

:SUBST
Set FName=%*
Set FHead=%FName:~0,3%
Set FBody=%Fname:~3%
Set FBody=%FBody:10M=%
Set FName=%FHead%%FBody%
If not "%*"=="%FName%" Echo Ren "%FDir%.\%*" "%FName%"
GoTo :EOF

I hope this helps, if anything goes wrong post again


0
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 Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Remove chacters from file names

Copy long file names from DOS? www.computing.net/answers/dos/copy-long-file-names-from-dos/6687.html

Long file name support in DOS-95? www.computing.net/answers/dos/long-file-name-support-in-dos95/2424.html

Long file names www.computing.net/answers/dos/long-file-names/5106.html