Validating uppercase/lowercase of user input with perl compared to unix folders
Hi,
I need to copy files from a source directory to a destination directory in unix.
I'm using the file::copy for the actual copy.
The problem is that the source and dest directories are supplied by different users, who might type the name of the directories in various combinations of lower case and upper case. This would be easy to solve, except no one kept here a naming standard, so the actual directories in unix can also be different combinations of uc and lc.
I was told that in most paths, only the two last directories would be in random case (that is: /Bla/Bla/Bla/random case/random case). I got around that by splitting the paths, taking the last two vars, then going over the directories with opendir and comparing everything under the directory to a non-case regex of the var I need ():
And this works... but what do I do in the case the folders before those two are also random case? Is there a simple recursive way to tackle this?
Also would this check:
work to make sure I found a directory and not a file?
I don't think this can be rigorously solved. UNIX will allow them to create many folders with the same name in different casing. How would users differentiate between them now?
How I'd handle it would be going through their folders and renaming them all lower-case for them.
If you're stuck with this mess, loop through whole folders converting everything to lowercase before comparing. If they match as lowercase, it's "correct", so use the unconverted mixed-case foldername.
Strange issue if I understood correctly. Names in Unix (most of them at least) are case sensitive, so users should provide the correct name and not leave you the job of searching for the correct one.
What about if the user gives you 'myFolder' and there are two of them, one 'myfolder' and other MYFOLDER?
I would use the grep() function instead open each dir and read all its contents.
So it could be /..../Prod/XX, /PROD/xx, /prod/Xx, whatever whoever created the folders felt like naming them. Also beneath them are Main or main or MAIN, and beneath that too - Scr, SCR, scr....
Then I might be supplied those same folder names as parameters in different combos.. and even if not, even if I always get the parameters in the same case, I still need to find out in what case exactly that folder is written in, because I need to transfer files there. Otherwise I would've used a lower case comparison like you suggested Corona688.
birei, so I can I use the code I wrote (I mean the same logic), but replace the whole opendir->while loop, with a grep?
Worst case scenario I'll give the users the responsibility (since they are in charge of whatever's in those directories) to find out how the folders are written and make sure the names they supply the script and the actual names correspond, themselves...
even if I always get the parameters in the same case, I still need to find out in what case exactly that folder is written in, because I need to transfer files there. Otherwise I would've used a lower case comparison like you suggested Corona688.
You can still compare them in lower case, just use the unconverted mixed-cased names from readdir after you've done so.
This will make it ambiguous when more than one identical name with different cases exists. Whichever comes first in the arbitrary listing order wins. I don't think you can avoid that.
Hello,
I have a list of files in a directory whose names are all in uppercasse, including the file format for eg *.MP3 . I would like to convert these to the normal way we write it ie ABC.MP3 to be converted to Abc.mp3 . I know that this can be done manually by using a lot of "mv" or rename... (6 Replies)
Hi,
how to convert user input (lowercase) to uppercase in the dos batch file ?
echo.
SET /p user1=Enter username:
SET user2=%user1%V
echo.
echo %user1%
echo.
echo %user2%
echo.
With Regards (7 Replies)
I'm trying to set up a script that takes user input and validates that the user input was entered correctly.
So far I have this:
while :
do
echo "Please enter your name."
read NAME
if
then
echo "You have not entered a name."
echo... (13 Replies)
I just started to learn unix...
and i needed to make a basic script.
i need to
1. read a file (.txt)
2. count the words of EVERY sentece
3. sentences with odd number of words need to be converted into lowercase
sentences with even number of words need to be converted into uppercase
... (6 Replies)
hi,
i need to write a bash script that does two things.
the program will take from the command line a file name, which is a C code, and an integer, which is the size of my indentation
i would then have to indent every nested code by the number of columns provided by the user in the... (1 Reply)
Inside a script I have 2 variables COMP=cy and PT=t. further down the same script I require at the same line to call those 2 variables the first time uppercase and after lowercase ${COMP}${PT}ACE,${COMP}${PT}ace. Can somebody help me
Thanks in advance
George Govotsis (7 Replies)
Trying to create a script in BASH that would ask the user to enter another user name making sure the input is not blank before they hit enter then to check the home directory of that user does exist, I have the check folder sorted it's just the loop to make sure the user has entered chars (5 Replies)
Greetings & Happy New Years To All!
A client of mine FTP'ed their files up to the server and it all ended up being in UPPERCASE when it all should be in lowercase. Is there a builtin command or a script anyone knows of that will automagically convert all files to lowercase?
Please advise asap... (4 Replies)