Remove [] from file name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
aveit
Posts: 8
Joined: 17 Oct 2011 05:16

Remove [] from file name

#1 Post by aveit » 08 Jul 2013 08:51

Hi

I have a number of files in a folder like below:

200002 - [20130708] - Test1
258258 - [20130907] - Test2

Is it possible to remove the [ and ] so i would be left with:

200002 - 20130708 - Test1
258258 - 20130907 - Test2

Many thanks
Paul

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Remove [] from file name

#2 Post by penpen » 08 Jul 2013 10:04

This could help if the files are in the current directory:

Code: Select all

@echo off
setlocal enableDelayedExpansion
for %%a in (*) do (
  set FILE=%%~a
  set FILE=!FILE:[=!
  set FILE=!FILE:]=!
  echo rename "%%~a" "!FILE!"
)
endlocal
goto:eof

penpen

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Remove [] from file name

#3 Post by foxidrive » 09 Jul 2013 01:13

If you use ! characters in your filenames, then ask for further help.

aveit
Posts: 8
Joined: 17 Oct 2011 05:16

Re: Remove [] from file name

#4 Post by aveit » 09 Jul 2013 05:26

Works perfectly for [ and ].

Would i be able to adjust this to replace
- page

with

_page

Many thanks
Paul

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Remove [] from file name

#5 Post by Squashman » 09 Jul 2013 06:23

aveit wrote:Works perfectly for [ and ].

Would i be able to adjust this to replace
- page

with

_page

Many thanks
Paul

Add this to the code.

Code: Select all

set FILE=!FILE:- page=_page!

Post Reply