Capitalize first letter in Files' names

Discussion in 'Plugin Development' started by rtainc, Feb 15, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    rtainc

    Hey everyone, how do I capitalize the first letter in a files' name (and change the name to that)?

    Currently, I use

    File configOld = new File("plugins/iMonies/config.yml");
    File configNew = new File("plugins/iMonies/Config.yml");

    if(configOld.exists() && !configNew.exists()) {
    configOld.renameTo(configNew);
    }

    But it decides that "config.yml" and "Config.yml" are the same name, as File is not case-sensative.
     
  2. Offline

    ZeusAllMighty11

    Why would you use the same name anyway?

    But you can convert string name toUpperCase() and save like that
     
  3. Offline

    rtainc

    No difference; that's the same as "File configNew = new File("plugins/iMonies/Config.yml");".
     
  4. Offline

    Tog

    if
    if(configOld.exists() && !configNew.exists()) {
    configOld.renameTo(configNew);
    }

    is working, why not add a third file and temporarily rename to that before switching to Config.yml? i.e. rename config.yml to temp.yml, then rename temp.yml to Config.yml
     
  5. It's not possible for one to exist and another not because they're the same file since, you've already said it, file names are case insensitive.

    You would have to get the actual name of the file and check if the first letter is lowercase then rename, no need for temporary files.

    I don't see the reason for this however...
     
Thread Status:
Not open for further replies.

Share This Page