I need a way to seperate a file location from the file itself (or the file name, to be specific). I’m developing a web-app, and I need to be able to pull out a file’s location and the file’s name seperately in order to link to them. I.e, if I have a file at web-app/files/foo/bar.bas, I need to be able to pull of 1.) web-app/files/foo/ and 2.) bar.bas.
I’m doing right now in Groovy (this is a Grails app), but I’m told that regex is much more efficient. I can use regex in Grails without trouble, but I am not familiar with it. I’m trying to learn it anyways, but I would greatly appreciate one of the gurus around here showing me who to hack this one.
The shell use commands like ‘dirname’ and ‘basename’. Most programming languages have functions to separate file and pathnames. They are normaly OS independant (not all), which means they would parse names correctly, whether the files are on a Unix or on a Windows servers. If you’re writing a web-apps, you should use such functions and NOT regexp. Read PHP, Perl, Python, java documentation … or whatever programming language you’re using.