1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to? @replace[a comma,_,filename]

Discussion in 'Support' started by Charles G, May 17, 2017.

  1. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,021
    Likes Received:
    0
    How can I replace a "," that is in a filename with a "_" ? Maybe escape the comma but not sure how to....
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,954
    Likes Received:
    30
    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
     
  3. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,021
    Likes Received:
    0
    Thanks Vince!
    So the answer is to use ^ as the escape char..... !
     
  4. dumbenis

    Joined:
    Yesterday
    Messages:
    2
    Likes Received:
    0
    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?

     
  5. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,190
    Likes Received:
    11
    Try putting the %@replace in quotes.
    Code:
    do f in "a_*" (ren "%f" "%@replace[_,^,,%f]")
    
     
  6. dumbenis

    Joined:
    Yesterday
    Messages:
    2
    Likes Received:
    0
    I tried to put the second %f in quotes, but this didn't work.
    Putting the %@replace[...] in quotes is the solution.
    Thanks!
     

Share This Page