Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

RFC: fixname v 0.3

by mulander (Monk)
on Jan 16, 2006 at 21:13 UTC ( [id://523606]=perlmeditation: print w/replies, xml ) Need Help??

Hello fellow Monks!
Yeasterday I had to scim through my old drive wich prevoisly was something that 'Windows' called it's home for a long time.

I am using linux for a long time now and I don't have to tell you how unfriendly it is to cd into a directory containing many spaces and being half upper case or even all upper case... and those very long names... I thought that something has to be done about it. And I asked myself why couldn't Perl help me at it?


So I set down and wrote a simple script that could make those names more friendly to me. I added a few features and now I would like to ask You for a opinion.


Here is the --help from this script:
Usage: ./fixname.pl options target target either a file or a directory This script changes file names to more user friendly ones Options: -h, --help display this help screen -V, --version display version information -S, --sub-space=X substitute spaces in the file name with a spec +ified char acter -s, --strip remove all spaces from the file name -l, --lower transfer all upper case letters in the filenam +e into low er case letters -u, --upper transfer all lower case letters in the filenam +e into upp er case letters -v, --verbose give verbose informations use multiple times t +o get even more verbose output -d, --dir-only only change directory names -f, --file-only only change file names -F, --force the script will change file names even if the +destinatio n name already exists -t, --trim=X trims the filename to given length ( must be m +ore than 0 length )


I have also started to write a .pod documentation for the script, my first one indeed so please fell free to criticise.

You can get both the script source and pod doc in tar.gz format from http://kewlnet.int.pl/~karql/fixname.tar.gz

What are my concerns right now?
Well the most irritating thing is fat type drives, because FILE and file are treated the same so --lower and --upper function by themselv won't change the filename ( it seems to work if used with something that changes characters in the file or its lenght like --trim or --subspace )
I was wondering if You could point me in a direction to solve this problem.

Another thing is about the features, those implemented are beacuse I found them useful, I would like to know what is useful for the most of us, is this script even worth further development?

I was thinking on adding --regex to allow direct control over file changing, but the question is should I give control over the whole regexp and pass it as an eval ? or take only the args double-check them and pass it into my preset regular expression? Should I allow the regex to modifie the file extension ( if it exists ? ); or should I forget about implementing regexps at all ?

Also I am wondering about the code, how do you find it? Is it passable ? In the means of efficiency, and maybe style? If not on what parts should I focus?

There is a second reason for this post, I thougth that maybe someone will find this useful like I did.


I am sorry for my grammar mistakes as english is not my native language.

Replies are listed 'Best First'.
Re: RFC: fixname v 0.3
by parv (Parson) on Jan 17, 2006 at 01:09 UTC
Re: RFC: fixname v 0.3
by samizdat (Vicar) on Jan 17, 2006 at 15:08 UTC
    I think you made a worthy programming exercise, and ESPECIALLY like your --help text, and pooh! on the AnonyMonk who dissed you. So what if TMTOWTDI??? I will add one suggestion to blazar's, which is:
    perl -e 'rename "./" . "\nbraindead\tname", "sensible_name"'
    which helps catch those pesky '-' at the beginning. :D

    Don Wilde
    "There's more than one level to any answer."
Re: RFC: fixname v 0.3
by Anonymous Monk on Jan 16, 2006 at 22:08 UTC
    I don't have any annoying directories on my linux machine! I don't create directories with spaces in the directory name. My linux installation didn't come with any spaces in the directory names. In general, the names are all lowercase, or at worse, mixed case. I don't have any problem with how my directories are named in the first place.

    You do know about filename (and directory) name completion features in your shell, right? It almost never matters exactly what the full file or directory name is, just that the first few letters are unique within the directory listing. Assuming that you structure your directories that way, file globbing or name completion make typing fairly minimal.

    In short, this module sounds a lot like a solution in search of a problem.

      I don't have any annoying directories on my linux machine! I don't create directories with spaces in the directory name.

      Me too! But what's nice is that in those rare situations in which I have to deal with (supposed to be) annoying filenames, I can do that effortlessly. I can have a file with a "\n" in it's name and the shell will expand it just as fine as any other one. Well... and if the "\n" is the first charachter? Whatever, when I'm totally lost -and it happens very rarely- mc or a tool like that comes to the rescue!

      A friend of mine also used to use mc to delete (or rename, etc.) files with a leading "-". That is, before he discovered that -- ends the list of options.

      In any case to keep the discussion on topic -that is, Perl- at the very worst one can use it ad hoc to deal with "exotic" filenames:

      perl -e 'rename "\nbraindead\tname", "sensible_name"'
Re: RFC: fixname v 0.3
by diotalevi (Canon) on Jan 18, 2006 at 22:07 UTC

    I tend to be of the opinion that software should be expected to do the right thing when dealing with files with spaces in them. That's utterly common in /home/*. I'd consider it a gross insult to have my tools insist that I not use spaces or other legal characters in my file or directory names.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://523606]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-19 21:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found