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? @replace[a comma,_,filename]

Apr
1,794
15
How can I replace a "," that is in a filename with a "_" ? Maybe escape the comma but not sure how to....
 
You could just rename the file. :-)
Code:
v:\> touch /c "a,b"
2017-05-17 00:53:43.424  V:\a,b

v:\> ren "a,b" a_b
V:\a,b -> V:\a_b
     1 file renamed

In any case, you'll have to rename it sooner or later. As you thought, escaping the comma in @replace works with little fuss.
Code:
v:\> do f in "a,*" (ren "%f" %@replace[^,,_,%f])
V:\a,b -> V:\a_b
     1 file renamed
v:\> do f in "a,*" (ren "%f" %@replace[^,,_,%f])
V:\a,b -> V:\a_b
1 file renamed
 
Thanks Vince!
So the answer is to use ^ as the escape char..... !
 
Thanks, works excellent: do f in "a,*" (ren "%f" %@replace[^,,_,%f])

At the end, I want to restore the original filename, renaming "_" with ","
Code:
do f in "a_*" (ren "%f" %@replace[_,^,,%f])
a_b -> V:\ab
Not the result I want. How to solve?

You could just rename the file. :-)
Code:
v:\> touch /c "a,b"
2017-05-17 00:53:43.424  V:\a,b

v:\> ren "a,b" a_b
V:\a,b -> V:\a_b
     1 file renamed

In any case, you'll have to rename it sooner or later. As you thought, escaping the comma in @replace works with little fuss.
Code:
v:\> do f in "a,*" (ren "%f" %@replace[^,,_,%f])
V:\a,b -> V:\a_b
     1 file renamed
v:\> do f in "a,*" (ren "%f" %@replace[^,,_,%f])
V:\a,b -> V:\a_b
1 file renamed
 
I tried to put the second %f in quotes, but this didn't work.
Putting the %@replace[...] in quotes is the solution.
Thanks!
 

Similar threads

Back
Top