You are not logged in.

#1 08 Oct 2017 20:06

imogene
Member
Registered: 08 Oct 2017
Posts: 5

rename - remove characters at end of filename

In a batch file, I am trying to remove a static set of characters from all files in a bunch of sub-directories.  I'd prefer to run the batch file on a set of files on a Win2000 box.

sample filename:  a_file_this.txt

Objective:  get the "a_file" part in a variable for later processing.

where are files in many sub-directories are 8 characters long or less not including the "_this" part.

where every file has same exact "_this" part.

where some files have the first underscore, others do not.  No more than one underscore not counting the "_this" part.

Either rename the entire file or get the "a_file" part into a variable.

My problem is the use of two underscores in the original filename prevents me from using DELIMS to target either the "a_file" or "_this" part.


thanks !

Offline

#2 08 Oct 2017 21:59

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: rename - remove characters at end of filename

I would read the entire filename into a variable and then manipulate it in memory

SET _filename=a_file_this.txt
SET _result=%_filename:_this=%

That should remove '_this' from the variable and return "a_file.txt" part into %_result%

This assumes you don't have any files named like '_this_file_this.txt'
for more see https://ss64.com/nt/syntax-replace.html

Offline

#3 09 Oct 2017 00:01

imogene
Member
Registered: 08 Oct 2017
Posts: 5

Re: rename - remove characters at end of filename

Perfect, thank you.  Appreciate the additional resource.

Offline

Board footer

Powered by