File path problem.
Posted: Tue Oct 04, 2005 8:56 am
I'm developing a file manager with PHP. It get's the files and directories, prints them out on the page, and uses links to call itself again.
For example, It prints out this:
The directory is now ./
If you click on etc/ it will change the directory to etc/ and print out this:
Directory is ./etc/
Now I click on X11/
The directory is now ./etc/X11/
I decide this is not the directory I want, so I click on ../ to go back one.
I am now in directory ./etc/X11/../
If I want to get out of etc, I click on ../ again.
The path is now ./ect/X11/../../
Now I want to go into the home directory:
The path to the directory is now ./ect/X11/../../home/
This pretty much gives you an idea of what I'm dealing with. After a while, your file path is full of ../ going in and out of directories jut to get to the one you want.
I think this is a waste of space and could be fixed easily with RegEx. But I'm not very good with it, so thats why I'm posting here.
What I need to do is that if the user presses ../ the script runs a function that removes the last directory in the path string, instead of adding ../ to the end.
For example: If I'm in directory ./etc/X11/ and I press ../ I want it to change the path to ./etc/
The only thing the RegEx needs to do is remove the last directory in the string along with the '/' after it.
Thank's in advance
For example, It prints out this:
The directory is now ./
Code: Select all
./
../
.mozilla/
bin/
boot/
dev/
etc/
home/
lib/Directory is ./etc/
Code: Select all
./
../
4Suite/
X11/
acpi/
alchemist/
alsa/
alternatives/
ant.d/
bluetooth/
bonobo-activation/
cron.d/
cups/
dbus-1/The directory is now ./etc/X11/
I decide this is not the directory I want, so I click on ../ to go back one.
I am now in directory ./etc/X11/../
If I want to get out of etc, I click on ../ again.
The path is now ./ect/X11/../../
Now I want to go into the home directory:
The path to the directory is now ./ect/X11/../../home/
This pretty much gives you an idea of what I'm dealing with. After a while, your file path is full of ../ going in and out of directories jut to get to the one you want.
I think this is a waste of space and could be fixed easily with RegEx. But I'm not very good with it, so thats why I'm posting here.
What I need to do is that if the user presses ../ the script runs a function that removes the last directory in the path string, instead of adding ../ to the end.
For example: If I'm in directory ./etc/X11/ and I press ../ I want it to change the path to ./etc/
The only thing the RegEx needs to do is remove the last directory in the string along with the '/' after it.
Thank's in advance