• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Can you force a Unix server via cPanel to ignore upper/lower case in file names?

Status
Not open for further replies.

goodcow

Member
Alright, so this weekend I decided to upload the 90,000 plus image files associated with the Sega news archive I have on my site since they only take about 300 megs total anyway...

The problem? While all the pages display fine locally in Windows, on my Unix server it's being a bitch and saying files aren't found just because of the upper/lower case states.

There's no way in hell I'm going to correct 90,000 files worth of file names and check how the HTML pages are referencing them in terms of upper/lower case, so I'm hoping there's some way to get the server to ignore that via cPanel or something...

Any ideas?
 

goodcow

Member
fart said:
no

do a global find/replace in the files instead so the anchors point to the right files

There are 5,000+ HTML files, with 5,000+ folders of a total of 90,000 image files, using IE6's "complete" save option.
 

xsarien

daedsiluap
goodcow said:
There are 5,000+ HTML files, with 5,000+ folders of a total of 90,000 image files, using IE6's "complete" save option.

Then you better get to work, I'm not sure this is something even Grep can tackle (I could be wrong, I'm basing that on never having *tried*.)
 

fart

Savant
there's no reason a global find/replace wouldn't work. you may have to take a coffee break while it runs though.

i just gave you the damn workaround! jesus.
 

xsarien

daedsiluap
fart said:
there's no reason a global find/replace wouldn't work. you may have to take a coffee break while it runs though.

i just gave you the damn workaround! jesus.

The problem may be doing it between files. Windows Grep may be able to tackle something like that.
 

fart

Savant
ultraedit and editplus both have respectable find/replace routines

is there even a windows grep?
 

goodcow

Member
fart said:
there's no reason a global find/replace wouldn't work. you may have to take a coffee break while it runs though.

i just gave you the damn workaround! jesus.

Can you elaborate? I thought you meant manually changing all the extensions to lowercase in the HTML files, one by one.

How exactly do I do a global find/replace, that sees what case state the HTML files are referencing, and changes them accordingly to the filenames?
 

CrunchyB

Member
Hahaha, you're screwed. Either you write a fairly complicated script, or you'll have to do it by hand.

If you're scripting, perhaps you convert every uppercase letter to lowercase, in both filenames and HTML anchors. That's quite doable and foolproof.
 

fart

Savant
eg, file is named "Goodcow.htm", but all anchors point to "goodcow.htm". do a recursive global find/replace from your top-level directory that finds "goodcow.htm" and changes it to "Goodcow.htm".

of course i'm assuming you have multiple casings in your anchors, so you'll have to either do a case insensitive search or if there are only a couple different casings you can do one s/r for each casing, as that's a bit safer.

obviously if you only have one casing in your anchors, just rename the file.

crunchyB's method would work too.
 

goodcow

Member
fart said:
eg, file is named "Goodcow.htm", but all anchors point to "goodcow.htm". do a recursive global find/replace from your top-level directory that finds "goodcow.htm" and changes it to "Goodcow.htm".

... so I can tell it to search for:

<img src=filename.GIF>

... and based on whatever the extension is, it'll check the local file it's calling, and if needed, change the case?

Here, just look at the mess of a directory so you're sure as to what I need done:
http://www.goodcowfilms.com/farm/games/news-archive/
 

fart

Savant
i'm not looking at that.

look, you have some string like "aBcDeFg" in a bunch of text files and you want them to say "ABCDEFG" right? so direct a program to search for "aBcDeFg" and replace it with "ABCDEFG".
 

goodcow

Member
fart said:
i'm not looking at that.

look, you have some string like "aBcDeFg" in a bunch of text files and you want them to say "ABCDEFG" right? so direct a program to search for "aBcDeFg" and replace it with "ABCDEFG".

That requires me to look at the HTML of all 5,000 or so HTML pages, and see WHAT exactly the filenames are SUPPOSED to be though.
 

fart

Savant
there are programs that will search a directory and recursively search all subdirectories for the requested string.
 

CrunchyB

Member
fart said:
there are programs that will search a directory and recursively search all subdirectories for the requested string.

But you'd still need to correct every single string seperately. And there are thousands of pictures, probably only referenced once or twice.

e.g.

replace_all pictureA.jpg picturea.jpg
replace_all pictureB.jpg pictureb.jpg
replace_all pictureC.jpg picturec.jpg

etc.

SO I SAY,

just rename both filenames and anchors to lowercase. But then that requires some moderately difficult scripting action.
 

maharg

idspispopd
Heh. Well if your provider provides mod_rewrite functionality you could probably work with that and a script that will rename every file to lowercase.
 

Hitokage

Setec Astronomer
This probably won't work so do not run this, but it's what comes to mind...

mkdir tmp
for x in *.html; do sed -e "s/src\=\(.*\.jpg\)/\L\1/g" $x > tmp/$x; done
cd tmp
for x in *.html; do mv $x `sed -e "s/\($x\)/\L\1/"`; done
 

goodcow

Member
Hitokage said:
This probably won't work so do not run this, but it's what comes to mind...

mkdir tmp
for x in *.html; do sed -e "s/src\=\(.*\.jpg\)/\L\1/g" $x > tmp/$x; done
cd tmp
for x in *.html; do mv $x `sed -e "s/\($x\)/\L\1/"`; done

o_O

That looks scary... can anyone comment on it?
 

xsarien

daedsiluap
If it looks scary, you shouldn't even bother with it.

I think the moral of the story is this:
You're boned unless you want to put a little virtual elbow grease into this.
 

Hitokage

Setec Astronomer
Sorry to bump this thread from oblivion, but I recently had to mass rename a bunch of files myself, and I thought of the idea I had in this thread. Actually got the concept working, and now I'll update my previous "do not attempt" post to "might have worked".

Here's a solution to goodcow's problem using bash, sed, and lots of regexp fun:

First the easy part, renaming all images in the same directory to lowercase:
Code:
for x in *.jpg *.JPG *.jpeg *.JPEG *.gif *.GIF; 
do mv "$x" "`echo "$x" | sed -e "s/.*/\L&/"`"; 
done

If your images are in different folders in the same directory... then this should work:
Code:
for x in */*.jpg */*.JPG */*.jpeg */*.JPEG */*.gif */*.GIF; 
do mv "$x" "`echo "$x" | sed -e "s/\(.*\/\)\(.*\)/\1\L\2/"`"; 
done

Changing all the references is tricky, since HTML treats all whitespace equally while sed does not. Breaking up tags across lines makes sed cry, but at least we know what we're looking for.
Code:
mkdir backup; 
for x in *.html *.htm; 
do mv "$x" "backup/$x"; 
sed -e "s/\(src=\"\)\(.*\)\(\.[Jj][Pp][Ee]?[Gg]\|\.[Gg][Ii][Ff]\|\)\(\"\)/\1\L\2\3\E\4/g" "backup/$x" > "$x"; 
done

Of course, I think goodcow already found a way to do it, but at least I wasn't totally crazy there.... although looking at those regexps again maybe I am.
 

xsarien

daedsiluap
Hitokage said:
Of course, I think goodcow already found a way to do it, but at least I wasn't totally crazy there.... although looking at those regexps again maybe I am.

A much easier solution - given that I don't wrestle with Unix anymore than I have to precisely because I want to avoid using Regex - is to do it locally from a CMD prompt on a Windows box. Obviously, this would be made easier if they're all in the same directory, or spread across only a few.

The following will work, as would the inverse:

rename *.gif *.GIF
 

xsarien

daedsiluap
Hitokage said:
I thought it was for any part in a filename with no pattern, not just the extension.

I'm not entirely sure, I'm going off what he posted:

Goodcow said:
... so I can tell it to search for:

<img src=filename.GIF>

In which case, in the interest of time, I'd say "Fuck parsing the code..." and just fix the extensions, assuming that's what's causing the problem given the example.
 

Hitokage

Setec Astronomer
Hmm... read the thread twice over... it's never made clear if it's just an extension issue, although I doubt that dropping a shitload of case insensitve file references into case sensitive environment is going to give you nothing more than that.

BTW, for my own mass rename I just had to take the number in the name of each file in a series then redo the name keeping the number. Bash/Sed saved me over 50 right click, properties, edit filename sessions.
 
Status
Not open for further replies.
Top Bottom