renaming directories from delimited text file? - Programmer

This is a discussion on renaming directories from delimited text file? - Programmer ; I have a situation where I have several directories which contain several subdirectories that I need to automatedly batch rename. The "roadmap" as it were which contains the before and after indications for the directories is contained in a comma-delimited ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: renaming directories from delimited text file?

  1. renaming directories from delimited text file?

    I have a situation where I have several directories which contain several
    subdirectories that I need to automatedly batch rename. The "roadmap" as
    it were which contains the before and after indications for the directories
    is contained in a comma-delimited text file. For example:

    A directory may contain something similar to:

    D00001
    D00002
    D00003
    D00004
    D00005

    where D00001 through D00005 are directory names. The text file, for
    example, would look like the following:

    D00001,F12345
    D00002,F23677
    D00003,F87102
    D00004,F79013
    D00005,F43016

    The goal is to be able to cause some kind of automated batch process where
    the contents of the text file will be used to perform actual renaming of
    the directory names. The directory named D00001 would become F12345; the
    directory named D00002 would become F23677, and so on.

    Is there an easy way in DOS to perform this? A batch file perhaps? (which
    I am lousy with) Visual Basic? (which I am versed enough in to get by...)

    Thanks for your help,
    Bailey

  2. Re: renaming directories from delimited text file?

    Bailey D. Williams wrote:
    > I have a situation where I have several directories which contain several
    > subdirectories that I need to automatedly batch rename. The "roadmap" as
    > it were which contains the before and after indications for the directories
    > is contained in a comma-delimited text file. For example:
    >
    > A directory may contain something similar to:
    >
    > D00001
    > D00002
    > D00003
    > D00004
    > D00005
    >
    > where D00001 through D00005 are directory names. The text file, for
    > example, would look like the following:
    >
    > D00001,F12345
    > D00002,F23677
    > D00003,F87102
    > D00004,F79013
    > D00005,F43016
    >
    > The goal is to be able to cause some kind of automated batch process where
    > the contents of the text file will be used to perform actual renaming of
    > the directory names. The directory named D00001 would become F12345; the
    > directory named D00002 would become F23677, and so on.
    >
    > Is there an easy way in DOS to perform this? A batch file perhaps? (which
    > I am lousy with)


    Not in MS-DOS and Windows 95, 98 or Me, but the Command Prompt in
    Windows NT, 2000, XP and Server 2003 can do this.
    Example (asuming the list file is called list.txt:

    for /f "tokens=1,2 delims=," %a in (list.txt) do ren "%a" "%b"

    In a batchfile you need double % signs:

    for /f "tokens=1,2 delims=," %%a in (list.txt) do ren "%%a" "%%b"

    Read the documentation about the for command for more info.

    > Visual Basic? (which I am versed enough in to get by...)


    With Visual Basic you should be able to find a solution compatible with
    more versions of Windows. Read the docs about e.g. the Input statement.

    --
    Olof Lagerkvist sm6xmk
    ICQ: 724451 @ssa.se
    Web: http://here.is/olof


  3. Re: renaming directories from delimited text file?

    You might consider using TEXTools (www.fireflysoftware.com). It's a
    text processing tool for Windows that allows you morph text from one
    form to another using the pipe / filters paradigm that everyone is
    familiar with. Granted, it's not a pure batch solution per se but
    then, from your post I gather you'd consider using a VB app... If the
    text is in a file named "in.txt" then the following two lines of
    TEXTools-endowed batch code will do the trick:

    type in.txt | tcl "replstr ',' ' ' | insstr 1 'rename '" >t$1.bat
    call t$1.bat

    This code formats each line into a rename command by first replacing
    the comma with a space and then inserting "rename " at the head of each
    line. Presto. You've now got a ready-to-run batch file that can then
    be executed on the very next line. Regards.

    Barry Block


+ Reply to Thread