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

Another problem with renaming files...

Discussion in 'Support' started by mathewsdw@sbcglobal.net, Jun 18, 2009.

Thread Status:
Not open for further replies.
  1. Background: I download files from an external site (that I have no control over) whose file names are constructed in a way that I absolutely hate! Among several issues is the fact that the file names contain underscores rather than blanks (i.e. This_is_a_sample_file_name.ext). Since I have gotten (and continue to get) a _lot_ of files from this site, I am trying to write a batch file that will rename them into a format that I don't absolutely despise automagically. (The complete set of renaming rules is well defined.) I was having problems with open parenthesis, but I got the solution from this site (Thanks again for that!). So the next problem is that I am unable to process file names that contain commas. (Specifically, %@Index[filename,_], for example, doesn't work if the file name contains comma(s). So the question is: is there a workaround of some kind for this problem? (I can't use the escape character ("^") in the file name variable because I am not building the original file names that I am trying to change.) Thanks in advance for any help you can give me!
     
  2. dbartt

    Joined:
    May 29, 2008
    Messages:
    36
    Likes Received:
    0
    For commas I would try %@replace[^,, ,%filename]. This would replace commas in
    %filename with a blank.

    Dennis
     
  3. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,187
    Likes Received:
    11
    I would rename the files first and then do your operations on them. A
    *lot* of hassle can be avoided by various combinations of SETDOS /X. Look
    up the help on SETDOS /X and see if that fixes your issue.

    I created a strangely named file and was able to rename it using @REPLACE
    to replace the commas with underscores.

    [C:\Temp\foo] >"this,is,a(funky)_file"

    [C:\Temp\foo] dir

    Volume in drive C is unlabeled Serial number is 5013:eee9
    Directory of C:\Temp\foo\*

    6/18/2009 11:16 <DIR> .
    6/18/2009 11:16 <DIR> ..
    6/18/2009 11:16 0 this,is,a(funky)_file
    0 bytes in 1 file and 2 dirs
    63,793,283,072 bytes free

    [C:\Temp\foo] ren "this,is,a(funky)_file"
    %@replace[^,,_,"this,is,a(funky)_file"]
    C:\Temp\foo\this,is,a(funky)_file -> C:\Temp\foo\this_is_a(funky)_file
    1 file renamed

    Here's another example:
    for %f in (*) do ren "%f" %@replace[^,, ,"%f"]

    I couldn't get delayed expansion to work properly. Rex or someone - can
    you explain why this doesn't work?

    [C:\Temp\foo] dir

    Volume in drive C is unlabeled Serial number is 5013:eee9
    Directory of C:\Temp\foo\*

    6/18/2009 11:36 <DIR> .
    6/18/2009 11:36 <DIR> ..
    6/18/2009 11:35 0 this,is,a(funky)_file
    0 bytes in 1 file and 2 dirs
    63,793,344,512 bytes free

    [C:\Temp\foo] ren * %%@replace[^,,_,"*"]
    C:\Temp\foo\this,is,a(funky)_file -> C:\Temp\foo\this,is,a(funky)_file]
    TCC: (Sys) The system cannot find the file specified.
    "C:\Temp\foo\%@replace["
    TCC: (Sys) The system cannot find the file specified.
    "C:\Temp\foo\_"
    1 file renamed

    [C:\Temp\foo] dir

    Volume in drive C is unlabeled Serial number is 5013:eee9
    Directory of C:\Temp\foo\*

    6/18/2009 11:36 <DIR> .
    6/18/2009 11:36 <DIR> ..
    6/18/2009 11:35 0 this,is,a(funky)_file]
    0 bytes in 1 file and 2 dirs
    63,793,340,416 bytes free


    Notice the commas were not replaced and a close bracket was appended to
    the name.

    -Scott

    "mathewsdw@sbcglobal.net" <> wrote on 06/18/2009
    01:44:26 AM:


     
  4. Thanks, guys! I changed the commas to question marks (which, as far as I know, can not appear in "valid" filenames) using the @Replace function as you suggested (I did not know the @Replace function even existed), and, when I was otherwise done manipulating the file names, I changed the question marks back to commas (I knew how to do that which is a good thing because @Replace doesn't seem to work in this instance...).
     
Thread Status:
Not open for further replies.

Share This Page