+ Post New Thread
Results 1 to 5 of 5
Scripts Thread, convert filenames to lowercase in Coding and Web Development; Ive got the following bash script: Code: #!/bin/bash for x in `ls` do if [ ! -f $x ]; then ...
  1. #1

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200

    convert filenames to lowercase

    Ive got the following bash script:

    Code:
    #!/bin/bash
    
    for x in `ls`
      do
      if [ ! -f $x ]; then
        continue
        fi
      lc=`echo $x  | tr '[A-Z]' '[a-z]'`
      if [ $lc != $x ]; then
        mv -i $x $lc
      fi
      done
    Which converts file-names to lowercase.

    The problem I'm having, is the folder I am trying to run it against, is a network share which the host file system is NTFS.

    The script is failing saying the original and new filename are the same. Is this because NTFS doesn't recognize different cases, or is there something wrong with the script?

    Is there an equivalent script I could run on the windows host to achieve the same thing?

  2. #2


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,646
    Thank Post
    229
    Thanked 865 Times in 743 Posts
    Rep Power
    297
    could you do it as a 2 stage script (yes messy) 1st stage renames as lower case but adds say an _ at the end of the filename 2nd stage renames without the _

  3. #3

    Join Date
    Apr 2009
    Location
    London
    Posts
    58
    Thank Post
    4
    Thanked 1 Time in 1 Post
    Rep Power
    0
    I think that NTFS doesn't distinguish between names with different case when performing operations such as open or rename.

    Your script lacks double-quotes, which you will need when dealing with filenames containing spaces. I've edited it below to add them (un-tested.)

    Actually, I've just realised that this could be a unicode problem. Try replacing the the tr line with
    Code:
    lc="$(echo "$x"  | tr '[:upper:]' '[:lower:]'`)"
    One simple way to get a better idea of what is going on would be to add "echo " at the start of the line which does the move, like this:
    Code:
    echo mv -i "$x" "$lc"
    This would show you what the commands were going to be, without executing them.

    Code:
    #!/bin/bash
    
    for x in `ls`
    do
      if [ ! -f "$x" ]; then
        continue
      fi
      lc="$(`echo "$x"  | tr '[A-Z]' '[a-z]'`)"
      if [ "$lc" != "$x" ]; then
        mv -i "$x" "$lc"
      fi
    done
    Last edited by Eric; 11th October 2011 at 03:19 PM. Reason: typo: s/exciting/executing/

  4. #4

    mattx's Avatar
    Join Date
    Jan 2007
    Posts
    9,240
    Thank Post
    1,058
    Thanked 1,068 Times in 625 Posts
    Rep Power
    740
    Powershell will do this quite easily:

    Windows PowerShell Tip: The String

  5. #5

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,804
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224
    Also be aware that windows explorer will alter the case of filenames before display in some circumstances. Use the command line to verify if the rename is working.

SHARE:
+ Post New Thread

Similar Threads

  1. [MS Office - 2010] Excel - Convert text to lowercase
    By FunkMaster_J in forum Office Software
    Replies: 7
    Last Post: 2nd June 2011, 10:45 PM
  2. Convert powerpoint to flash?
    By dave.81 in forum Office Software
    Replies: 10
    Last Post: 24th July 2007, 08:28 AM
  3. Convert MP3 to AAC in iTunes
    By richard in forum General Chat
    Replies: 12
    Last Post: 22nd January 2007, 11:21 AM
  4. Convert DVD to AVI or MPEG or something
    By adamyoung in forum How do you do....it?
    Replies: 6
    Last Post: 29th March 2006, 10:30 PM
  5. Convert .mrw to .jpg
    By richard in forum Windows
    Replies: 6
    Last Post: 28th February 2006, 01:21 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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