Results 1 to 7 of 7
Like Tree5Likes
  • 3 Post By Norm
  • 1 Post By jim829
  • 1 Post By gimbal2

Thread: Mass Renaming of Files

  1. #1
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Mass Renaming of Files

    Hi.

    I have a set of files that are in folders.

    All of the files are named the same thing...File1

    The folder name that they are in actually has the name of the thing that is on the file.


    Long story short, I'm trying to figure out how I can write a program that will rename all of the files with a .ape ending to the name of their folder.

    If you could push me in the right direction and give me some commands to learn, that'd be great.

    Thanks

  2. #2
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: Mass Renaming of Files

    You could get the folder that contains all of the folders, and iterate over all of file sub-files/directories recursively, and take any file whose name contains .ape and rename it to the name of the parent directory.
    1000011 1100001 1101110 100000 1111001 1101111 1110101 100000 1110010 1100101 1100001 1100100 100000 1000010 1101001 1101110 1100001 1110010 1111001 111111

  3. #3
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Re: Mass Renaming of Files

    My issue isn't the algorithm - it's the actually way to get, rename, and navigate through files and folders.

  4. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,648
    Rep Power
    5

    Default Re: Mass Renaming of Files

    Check out the java.io.File class. You can test for directories and use the methods for loading the contents.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,515
    Rep Power
    25

    Default Re: Mass Renaming of Files

    A suggestion for testing the code:
    Have a debug mode that prints out the renames that the code will do instead of doing the renames. That will show you what the code will do when debug mode is turned off. That will save you from disaster if there is a bug in the code.
    jim829, gimbal2 and AlexGraal like this.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,648
    Rep Power
    5

    Default Re: Mass Renaming of Files

    To supplement Norm's excellent advice (having been there myself), you may also want to copy a directory hierarchy similar to what you are renaming to use as a first real test. If it fails to work as expected, simply delete the hierarchy, recopy it, fix your code, and try again. In fact, if you have the space, simply change a copy of what you want to alter. Then if it looks okay, you can delete the original.

    Regards,
    Jim
    Norm likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,049
    Rep Power
    6

    Default Re: Mass Renaming of Files

    Quote Originally Posted by Norm View Post
    A suggestion for testing the code:
    Have a debug mode that prints out the renames that the code will do instead of doing the renames. That will show you what the code will do when debug mode is turned off. That will save you from disaster if there is a bug in the code.
    A "dry run" mode; very good suggestion.
    Norm likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Mass Effected
    By TheCEL in forum Reviews / Advertising
    Replies: 0
    Last Post: 03-23-2012, 12:37 AM
  2. Body Mass Index Calculator
    By bentho in forum New To Java
    Replies: 3
    Last Post: 11-01-2010, 03:05 AM
  3. Mass storage
    By MIA6 in forum New To Java
    Replies: 4
    Last Post: 11-02-2009, 06:22 PM
  4. Best GUI Element to Display Mass Data
    By hannehomuth in forum Advanced Java
    Replies: 3
    Last Post: 07-29-2008, 11:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •