+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, script to capitalize first letter of words, separated with full stop in Coding and Web Development; Just wondering if someone could knock us up a simple script, bash, or perl, or python, or whatever is easiest.. ...
  1. #1

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

    script to capitalize first letter of words, separated with full stop

    Just wondering if someone could knock us up a simple script, bash, or perl, or python, or whatever is easiest..

    basically just looking to try to change

    this.is.the.filename.ext

    to

    This.Is.The.Filename.ext

    Thanks in advance

  2. #2

    Join Date
    Apr 2007
    Location
    Birmingham
    Posts
    145
    Thank Post
    6
    Thanked 45 Times in 39 Posts
    Rep Power
    23
    Not a script, but this may help - Renamer is quite useful for file renaming.

    You can add a case rule to captialise every word which should do what you require.

  3. #3

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,532
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    sorry should have stipulated.. im not running windows.

  4. #4
    Arcath's Avatar
    Join Date
    Feb 2009
    Location
    Lancashire
    Posts
    980
    Thank Post
    103
    Thanked 117 Times in 102 Posts
    Rep Power
    74
    does the script need to look through a given directory? or will you just pass a filename to it?

    is ruby allowed?

  5. #5

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,532
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    yeh preferably to traverse through a whole directory tree

    Never used Ruby before, but I can install it no worries ...

  6. #6
    monkeyx's Avatar
    Join Date
    Nov 2006
    Posts
    365
    Thank Post
    8
    Thanked 52 Times in 41 Posts
    Rep Power
    26
    Here is a pyhton script that I use where I use the string.title() function to do what you are asking for. It does also captize the extension, but sure you could work out how set the last 3 chars to lowercase

    Code:
    #!      /usr/bin/python
    #       Copyright 2008 Thura <thurahlaing06@gmail.com>
    #       Just a small script to rename files and folders in nautilus recursively
    #       Tested under Ubuntu 8.04, should work fine with other Linux dist ...
    
    
    import os,sys,string
    dirs = []
    def ren(path):
        oldname = os.path.split(path)[1]
        newname = oldname.title()
    
        print 'Renaming ' + oldname + ' to ' + newname;
          #Change this line for your preferred filename ...
        #For example, newname = oldname.lower()
        #             newname = "Your Prefix" + oldname <or>
        #             newname = oldname + "Your suffix"
        newpath = os.path.join(os.path.split(path)[0],newname)
        os.rename(path,newpath)
        if os.path.isdir(newpath):
            for name in os.listdir(newpath):
                ren(os.path.join(newpath,name))
    for i in sys.argv[1:]:
        dirs.append(i)
    for dir in dirs:
        ren(dir)

  7. Thanks to monkeyx from:

    RabbieBurns (24th September 2009)

  8. #7

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,532
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    That works great, cheers.

    Its no big deal about the last 3 chars I guess..

    Thanks again

  9. #8

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,532
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    Code:
    #!      /usr/bin/python
    #       Copyright 2008 Thura <thurahlaing06@gmail.com>
    #       Just a small script to rename files and folders in nautilus recursively
    #       Tested under Ubuntu 8.04, should work fine with other Linux dist ...
    
    
    import os,sys,string
    dirs = []
    def ren(path):
        oldname = os.path.split(path)[1]
        newname = oldname.title()
    
        temp = newname.split(".")
        temp[-1] = temp[-1].lower()
        newname = ".".join(temp)
    
        print 'Renaming ' + oldname + ' to ' + newname;
          #Change this line for your preferred filename ...
        #For example, newname = oldname.lower()
        #             newname = "Your Prefix" + oldname <or>
        #             newname = oldname + "Your suffix"
        newpath = os.path.join(os.path.split(path)[0],newname)
        os.rename(path,newpath)
        if os.path.isdir(newpath):
            for name in os.listdir(newpath):
                ren(os.path.join(newpath,name))
    for i in sys.argv[1:]:
        dirs.append(i)
    for dir in dirs:
        ren(dir)
    Modified to lowecase the last word.. which works perfectly..

    Thanks again.

  10. #9
    monkeyx's Avatar
    Join Date
    Nov 2006
    Posts
    365
    Thank Post
    8
    Thanked 52 Times in 41 Posts
    Rep Power
    26
    Great News



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 9
    Last Post: 9th April 2009, 08:33 AM
  2. Replies: 0
    Last Post: 16th September 2008, 09:56 AM
  3. Replies: 28
    Last Post: 28th November 2006, 04:32 PM
  4. Certain letter keys stop working
    By EL_S in forum Windows
    Replies: 4
    Last Post: 9th June 2006, 05:37 PM
  5. Words fail me #2
    By KarlGoddard in forum General Chat
    Replies: 14
    Last Post: 1st March 2006, 11:51 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
  •