Welcome!

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

SignUp Now!

Filenames with ";"

Apr
1,808
17
I want to replace filenames that contain ";" with "_". I can't even get plain DIR to find the files.

Code:
for %fn in ("*;*") ren "%fn" "%@replace[;,_,%fn]"

dir /a:-d /b /s "*;*"

Both do not work.

@vince - would this be a good char to have your fixnames plugin to work on?
 
I want to replace filenames that contain ";" with "_". I can't even get plain DIR to find the files.

Code:
for %fn in ("*;*") ren "%fn" "%@replace[;,_,%fn]"

dir /a:-d /b /s "*;*"

Both do not work.

Interesting. Both of the above work for me (under TCC 20.00.14 x64 — Windows 10 Pro). The renaming worked fine:

D:\temp> for %fn in ("*;*") ren "%fn" "%@replace[;,_,%fn]"
D:\temp\test2;hello.txt -> D:\temp\test2_hello.txt
1 file renamed
D:\temp\test3;goodbye.txt -> D:\temp\test3_goodbye.txt
1 file renamed
 
It doesn't seem much different from the comma (except that I couldn't make one with TOUCH).
Code:
v:\> echo foo > "a;b.txt"

v:\> d "*;*"
2017-05-17  12:11               5  a;b.txt

v:\> do f in "*;*" (ren "%f" %@replace[;,_,%f])
V:\a;b.txt -> V:\a_b.txt
     1 file renamed
 
Suggestion for a future version: Allow the vertical bar | as an include-list separator, behaving just the same as the semicolon. Then in some more-distant-future version, the semicolon could be deprecated.... Filespecs containing a vbar would need to be quoted, of course, just like spaces, ampersands, et cetera.

(The choice of semicolon for this function goes back to 4DOS. IIRC, semicolon was not a legal filename character in DOS, so it made sense at the time.)
 
And what would we do with pipes? And a jillion batch files and aliases using pipes?

You already have that part implemented. A vertical bar between quotes has no special meaning.

Code:
C:\>dir "*.bat|*.cmd|*.btm"

 Volume in drive C is Hard Drive     Serial number is 6218:b594
TCC: (Sys) The system cannot find the file specified.
 "C:\*.bat|*.cmd|*.btm"
                   0 bytes in 0 files and 0 dirs
     156,308,537,344 bytes free

C:\>
 
Not sure what you're getting at -- a semicolon between quotes has no special meaning either.
Is that so? Why did my first attempt to create "a;b" fail?
Code:
v:\> touch /c "a;b"
2017-05-17 20:28:38.034  V:\b
And there seems to be a special meaning here also.
Code:
v:\> *dir /a /p /m /k /h /ne "a;b"
2017-05-17  20:28               0  b
 
What's going on with TOUCH? Below, it created only "b".
Code:
v:\> touch /c "a;b;c"
2017-05-17 21:52:14.842  V:\b
 
What's going on with TOUCH? Below, it created only "b".
Code:
v:\> touch /c "a;b;c"
2017-05-17 21:52:14.842  V:\b
I didn't quite have that figured out. Using TOUCH /C "a;b;c", if any exist it'll touch (only) them; in none exist, it'll create only the last one specified.
 
Not sure what you're getting at -- a semicolon between quotes has no special meaning either.
Difference being that the semicolon is a valid (if silly) filename character, and the vertical bar is not.
 

Similar threads

Back
Top