Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Work with Filenames Containing Brackets "[" and "]"

Jan
3
0
Hi. Sorry if this has been asked before - I searched, but couldn't find anything on it.

I have a bunch of files at work (mixed in with others) where the square brackets "[]" are included in the filename.

I'm trying to figure out how to do some renaming stuff on all files EXCEPT those files.

For example:

Ledger_04-08-2016_Sans_Pers_Info.xls
Agenda items from April 11, 2016 luncheon.doc
Legal notes [Don'tModify] April 2016 - AZD .txt

I want to re-name the first two files, and leave the last one alone. (Note that this is a simple example, the actual filenames get much stranger, and the only reasonably consistent thing is that files with notes [in brackets] shouldn't be messed with).

I've tried about a thousand patterns and such, and they all seem to fail when it comes to square brackets. Any help?

Thanks!
 
Thanks Charles.

dir /[!*[*]
seems to work when that's the only consideration. But part of the project is "grouping" the files by other text in the filename as well, which the user is prompted for earlier on in the code. I've got everything working/filtering/grouping fine except when there's "[" characters in the filename. Plus, of course, there's the whole "spaces in filenames" issue, and so on.

I finally did get it to work using EXCEPT around my FOR/DO constructs. It throws an error if there's a subdirectory in there, but the rest of it works fine. I seem to recall that EXCEPT used to have a switch (I thought it was /i) to ignore errors, but that doesn't seem to work. I think that was way back in the 4DOS days, so memory may be incorrect.

So first I'm using DIR to inform the user what files will be affected:
EXCEPT (*[*) DIR /K /M "%N%*.*"

Then if they say okay, I'm carrying out the actual manipulations with:
EXCEPT (*[*) FOR %A IN ("%N%*.*") DO ( ... )

Anyway, the EXCEPT error shows, but doesn't halt progress, so I've got the thing working. It'd be cleaner without the errors, but oh well!

Thanks again for your input!

- AzDayton Wed. 04/13/2016 @ 13:57
 
Back
Top
[FOX] Ultimate Translator
Translate