Need to write a batch file to rename lots of folders

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moorcroft
    New Member
    • Mar 2008
    • 57

    Need to write a batch file to rename lots of folders

    I've never really written batch files before and don't know syntax etc so am looking some help. My folder structure is as follows:

    c:\applications \ contains a list of folders for example:

    c:\applications \100000\ , c:\applications \200000\ etc

    and in each of these folders there are lists of folders named by the applications primary key, for example:

    c:\applications \100000\154523\ application_for m.pdf
    c:\applications \100000\128042\ application_for m.pdf
    c:\applications \200000\274398\ application_for m.pdf
    etc

    Basically the problem I have is that the primary key is wrong for each one as it uses a primary from a different database. Therefore each folder name will need to be updated. There are thousands of applications so I'd have to query the application_num ber from test database using primary key then query the live database with the application_num ber to get the new primary key. This is unfeasible so I need a batch file to do this for me.

    The following are the list of steps that it'd need:

    for each folder in c:\applications \
    {
    for each folder in c:\applications \<foldername>
    {
    sqlplus <user>/<password>@<tes t_database>;
    select application_num ber from applications where pk = <foldername>;
    variable appNumber = application_num ber;
    exit; //close test database

    sqlplus <user>/<password>@<liv e_database>;
    select pk from applications where application_num ber = appNumber;
    int folderName = (pk / 1000) * 1000; //turn 153242 into 100000
    new folder c:\applications \<folderName>\< pk>\application _form.pdf;
    exit; //close live database
    }
    }

    I'd appreciate any help as I've never written a batch file to do this sort of thing!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Which language are you using?

    Comment

    • Nepomuk
      Recognized Expert Specialist
      • Aug 2007
      • 3111

      #3
      Well, as it's a batch file, I guess the OP means batch scripting for Windows.

      Greetings,
      Nepomuk

      Comment

      Working...