File Path Fixer

Miscellaneous Forums/General Discussion/File Path Fixer

I am trying to compile a program using Linux. Unfortunately, the source code for this particular program is filled with improper caps in file names and is extremely large.

So, does anyone know of a program which will go through the source code and fix file path caps?
I could write one myself, but I'm too lazy, and the resulting program wouldn't help anyone other than myself.

Just use Find/Replace, surely?

Couldn't you just write the program correctly?

Noel: I didn't write the program.
It is a C++ program called Moonshell, written for DevKitPro with libNDS.


Banshee: I could use find&replace, but the process would take centuries because the source code is ginormous and is spanned across hundreds of files. (These files are also distributed into many many different directories which are children of either source\arm7 or source\arm9, along with a bloody massive Plugins directory in the Arm9 section and piles of others.)
I was doing Find&Replace previously before I gave up, but it was getting pretty slow and complicated. (The deeper I got into the mess, the longer it took to compile the program up to the next broken Include so I could figure out what to fix next).

The project file is for an IDE that only works in Windows.

No, there is no good reason why I am determined to compile this with Linux except that I much prefer it when programming for this particular device.


I guess the simplest form of the program I want would recursively scan for files in specific directories and for each file it would find and replace in the source code to fix case issues. That would probably take longer than doing it by hand...
The other more sensible option, I guess, is for it to actually read the source code, check for Include statements, find the included file, and fix the case.


Unless someone else has written a similar program (someone must have had the same trouble as me, after all this time!), I guess I'll do this thing :(

That would probably take longer than doing it by hand...


Sounds like a twenty line Perl program.

Sounds like a twenty line Perl program.
Not writing the program, but running it.
Lots of files...

That thought would do the following: For every single file, the program would loop through every single other file, searching for references to that file's name. It would do this exact same process about 200 times unless I could be bothered to do it properly. (Which I cannot be bothered to do).

Write a quick perl/ruby/etc. script to go through the files and fix paths.

If it's too much trouble to do that, then you might as well give up now.

Perl's regular expression engine is extremely fast at finding patterns (such as "path/path/filename.extension"). I can't imagine this Perl script taking longer than a couple minutes to run over 200 huge files - but it'd probably take 10 seconds if you use s///eg with a hash table lookup. Even if it takes eight hours, it could save you time: leave it running while you sleep!

If you know what the file/folder names are likely going to be, this one might be useful:

(Windows application) InfoRapid Search & Replace -- http://www.inforapid.de/html/searchreplace.htm , a nice freeware utility that can do global search & replacing across entire directory structures.

It has saved me countless of hours updating things when having to deal with websites that had thousands of pages of identical static data rather than just use a stupid include file...

In this case, you can probably do a search, tell it NOT to be case sensitive to find both upper case and lowercase matches, and replace them by the lowercase version.

Under Linux its possible to cobble up scripts that do the same, using the nifty 'sed' command.

Cool!
Thanks, xlsior! That's what I was hoping for; a solution where I don't have to bother using my head.

Perl = sed + awesome

Mr. Picklesworth: you may have the wrong hobby/profession if you don't like using your head!

If you're just trying to get the source to compile, one really kludgy workaround would be to store the source code on a windows box, and compile on your linux box via a mounted Samba share across the network pointing to the windows box.

One of the interesting side-effects of Samba is it makes file access to windows boxes case insensitive.

octothorpe: Who says I don't like using my head?
Edit: Oh, me 3 hours ago. Damn him!

I'm just busy using my head with other, more fun stuff.


What's wrong with working out the most sleek technique to do this which has the least chance of calling the fatal command that kills my hard drive?
I think it's a worthy exercise :)

Nice suggestions so far. I'll keep them all in mind. They apply to all sorts of different situations involving nitwits writing enormous programs but failing to use proper cases in filenames. This may help more people than just me -- it's a good collection of knowledge.

One of the interesting side-effects of Samba is it makes file access to windows boxes case insensitive.


Good suggestion!

If you have BlitzMax you could have a peek at the CasedFileName function in stream.mod.