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

renaming files

Discussion in 'Support' started by gunkelkarl, Jun 15, 2008.

  1. gunkelkarl

    Joined:
    Jun 15, 2008
    Messages:
    5
    Likes Received:
    0
    I must rename a big number of files. The old name is
    xxxxxx_0001.jpg,
    xxxxxx_0001.jpg,
    xxxxxx_0001.jpg
    ......

    the new name should be
    00001.jpg
    00002.jpg
    .....
    00010.jpg
    .....

    I am not so familar with takecommand, so I need help
    Thanks in advance
    Karl
     
  2. jmcm

    Joined:
    Jun 11, 2008
    Messages:
    26
    Likes Received:
    0
    gunkelkarl wrote:

    Do you really have identical existing filenames as illustrated above?



    Karl

    You really need to provide more info on what you have and the result you
    want and in this case what is the relationship between the source name
    and the target name.

    --
    Regards
    John McMahon
    lists@jspect.fastmail.fm

    http://catb.org/~esr/faqs/smart-questions.html
     
  3. vpdura

    Joined:
    Jun 3, 2008
    Messages:
    27
    Likes Received:
    0
    On Mon, 16 Jun 2008 05:35:37 -0500, jmcm <> wrote
    Re RE: [Support-t-199] renaming files:


    Or, if you have to do this kind of renaming often, you can just try
    the freeware ReName Master.

    http://www.joejoesoft.com/cms/showpage.php?cid=108

    I use it often. It's very good.
    --
    At first they laugh at you, then they ignore you, then they fight you, then you win.
     
  4. gunkelkarl

    Joined:
    Jun 15, 2008
    Messages:
    5
    Likes Received:
    0
     
  5. Rex Clark

    Joined:
    May 30, 2008
    Messages:
    57
    Likes Received:
    0
     
  6. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    gunkelkarl wrote:
    |
     
  7. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    Rex Clark wrote:
    |
    | QuickNDirty.BTM
    |
    | dir /b *.jpg >input.dat
    |
    | do r=0 to %@lines[input.dat]
    | set fifo=%@line[input.dat,%r]
    | ren /N %fifo %@instr[%@inc[%@index[%fifo,_]],,%fifo]
    | enddo

    Your method is very slow because of the manner @LINES works. Furthermore,
    splitting the name via @INSTR[] after locating the proper location using
    @INDEX is superfluous according to the file name formats in the modified OP.

    An equivalent method, without the need for the auxiliary file, is in my
    response to the OP.

    |
    | "NOTE" /N(othing) after "ren"ame remove "/n" when you are sure this
    | is what you want it to do.

    An excellent point. I usually put the /n at the tail end of the command
    (esp. interactively) for easier removal.
    --
    Steve
     
  8. gunkelkarl

    Joined:
    Jun 15, 2008
    Messages:
    5
    Likes Received:
    0
    Steve, thanks!
     
  9. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    gunkelkarl wrote:
    | Steve, thanks!

    You're welcome.
    --
    Steve
     
  10. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,201
    Likes Received:
    11
    I was going to suggest using the newer syntax of regular expressions and
    delayed expansion to accomplish the task in a single rename statement but
    I think I've uncovered a glitch.

    I created 10 files:
    for /l %c in (1,1,10) do echo. >file_%@format[04,%c].jpg

    Then I created an 11th special case:
    echo. >file_0011a.jpg

    Then I tried to rename it using this syntax:
    ren /n "::.*_\d\d\d\d\.jpg" %%@right[8,*]

    Which in theory should rename the files (with the exception of the 11th)
    to the last 4 digits and the extension.

    @name appears to work but @right is failing miserably.

    -Scott

    Steve F畸i疣 <> wrote on 06/16/2008 09:16:06 AM:


     
  11. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    samintz wrote:
    | I was going to suggest using the newer syntax of regular expressions
    | and delayed expansion to accomplish the task in a single rename
    | statement but
    | I think I've uncovered a glitch.
    |
    | I created 10 files:
    | for /l %c in (1,1,10) do echo. >file_%@format[04,%c].jpg

    Two independent simplifications.
    1/ Use touch/c to create empty files.
    2/ Use for/l %c in (10001,1,10010) in the loop, and use %@right[4,%c] in the
    file name. This is simpler in some contexts, though in the present context
    may not actually be faster or easier to understand. BTW, I have UDFs for
    fz2=`%@format[02,%1]` through fz9 to simplify the task using your control
    variable.
    |
    | Then I created an 11th special case:
    | echo. >file_0011a.jpg
    |
    | Then I tried to rename it using this syntax:
    | ren /n "::.*_\d\d\d\d\.jpg" %%@right[8,*]
    |
    | Which in theory should rename the files (with the exception of the
    | 11th)
    | to the last 4 digits and the extension.
    |
    | @name appears to work but @right is failing miserably.

    Using TCC 9.02.151 Windows XP [Version 5.1.2600] (in its own window) I
    found the same issue with the command

    ren *_[0-9][0-9][0-9][0-9].jpg %%@right[8,*]

    the target names were identical to the source names. However, puuting
    quotation marks around the target name thus:

    ren *_[0-9][0-9][0-9][0-9].jpg "%%@right[8,*]"

    worked like a charm. It properly renamed files 1..10, and left alone the
    "1a" file.
    --
    Steve
     
  12. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,994
    Likes Received:
    84
    samintz wrote:

    Nothing to do with @RIGHT; the problem is because you've failed to quote
    the target. The ',' inside @RIGHT is being interpreted as an argument
    separator (whitespace), so REN thinks the target filename is supposed to
    be "*]". I tried it here with the quotes in place and it worked as
    expected.

    Rex Conn
    JP Software
     
  13. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,201
    Likes Received:
    11
    Cool beans!

    So an actual syntax that works is:
    ren "::.*_\d+\.jpg" "%%@right[8,*]"

    The RegEx says: zero or more of any character (.*) followed by underscore
    (_) followed by 1 or more numeric digits (\d+) followed by .JPG (\.jpg).
    Delayed expansion can then be used to manipulate the name anyway you want.

    However, I tried to get a more generic solution for a file that starts
    with arbitrary characters, an underscore, followed by an arbitrary number
    of digits, then .jpg. The @right works above because the filenames all
    have 4 digits at the end of their names. So I tried to use @REGEXSUB.

    ren /n "::.*_\d+\.jpg" "%%@regexsub[1,(\d+)$,%%@name[*]].jpg"

    This works:
    echo %@regexsub[1,(\d+)$,%@name[file_0001.jpg]]
    0001

    But the REN statement does not. What's wrong with my syntax?
    -Scott

    rconn <> wrote on 06/16/2008 02:58:55 PM:



    and

    but

    11th)



     
  14. Rex Clark

    Joined:
    May 30, 2008
    Messages:
    57
    Likes Received:
    0
    Why would %@lines matter it only needs to know how many lines to read in the file .. it s only done once. so theres 2343 lines it takes less than 2 seconds to get what it needs to continue.

    as for %@line[] its got its filename "%r" profides the next line number

    I could of used fileread/open/seek
    To much syntax for a simple job when the above does what its told ... given the translation i got from his original post in regards to his file re-naming criteria. it was "QuickNDirty" no testing of complex regexp

    regular expressions would of work too

    I find having code/scripting whatever easier todo if the code itself was more descriptive than writting "comments under or above the syntax to explain what it does". I hate comments they are sometimes more confusing than the actual code. But thats just me.
     
  15. Rex Clark

    Joined:
    May 30, 2008
    Messages:
    57
    Likes Received:
    0
    I must respond with a Sorry to All..
    I re-read his original post and found that the file naming criteria he
    requested
    would not work in this QuickNDirty.BTM

    a) xxxxxx_0001.jpg, xxxxxx_0001.jpg,xxxxxx_0001.jpg
    all the same endpoints 0001.jpg

    QuickNDirty was expecting _0001.jpg _0002.jpg etc.. in auxiliary file
    "input.dat"

    Sorry Steve .. and anyone else who thought I was an idiot.

    ----- Original Message -----
    From: "Rex Clark" <>
    To: <rexxc@slingshot.co.nz>
    Sent: Tuesday, June 17, 2008 2:47 PM
    Subject: RE: [Support-t-199] Re: renaming files


    : ---Quote (Originally by Steve Fbin)---
    : Rex Clark wrote:
    : |
    : | QuickNDirty.BTM
    : |
    : | dir /b *.jpg >input.dat
    : |
    : | do r=0 to %@lines[input.dat]
    : | set fifo=%@line[input.dat,%r]
    : | ren /N %fifo %@instr[%@inc[%@index[%fifo,_]],,%fifo]
    : | enddo
    :
    : Your method is very slow because of the manner @LINES works. Furthermore,
    : splitting the name via @INSTR[] after locating the proper location using
    : @INDEX is superfluous according to the file name formats in the modified
    OP.
    :
    :
    : An equivalent method, without the need for the auxiliary file, is in my
    : response to the OP.
    :
    : |
    : | "NOTE" /N(othing) after "ren"ame remove "/n" when you are sure this
    : | is what you want it to do.
    :
    : An excellent point. I usually put the /n at the tail end of the command
    : (esp. interactively) for easier removal.
    : --
    : Steve
    : ---End Quote---
    : Why would %@lines matter it only needs to know how many lines to read in
    the file .. it s only done once. so theres 2343 lines it takes less than 2
    seconds to get what it needs to continue.
    :
    : as for %@line[] its got its filename "%r" profides the next line number
    :
    : I could of used fileread/open/seek
    : To much syntax for a simple job when the above does what its told ...
    given the translation i got from his original post in regards to his file
    re-naming criteria. it was "QuickNDirty" no testing of complex regexp
    :
    : regular expressions would of work too
    :
    : I find having code/scripting whatever easier todo if the code itself was
    more descriptive than writting "comments under or above the syntax to
    explain what it does". I hate comments they are sometimes more confusing
    than the actual code. But thats just me.
    :
    :
    :
    :
    :
     

Share This Page