Don't ask to ask, just ask | |
PerlMonks |
Is this directory a subdirectory of another directory?by mt2k (Hermit) |
on Mar 15, 2002 at 06:37 UTC ( [id://151919]=perlquestion: print w/replies, xml ) | Need Help?? |
mt2k has asked for the wisdom of the Perl Monks concerning the following question:
Okay, I believe that this is a weird question. Not the question itself, but how I'm going to explain it! I think the easiest way to start is to give an example of a directory structure (I'm using Win32, so I'll use Win32 paths):
Now, say that the string "C:/Apache/www-root/images/bgs" is passed to the CGI script and stored in $input{'directory'}. Let's say that $input{'directory'} is the name of the directory I want to copy to another directory somewhere on the system, specified as $input{'copy_to'}. Here's the code that accomplishes this:
But there is a small problem with this code! If $input{'directory'} is "C:/Apache/www-root/images" and $input{'copy_to'} is "C:/Apache/www-root/images/bgs", the copy does a horrible thing. It continually, over and over again, copies the C:/Apache/www-root/images directory deeper and deeper into directory C:/Apache/www-root/images/bgs, so that one gets a filesystem such as this:
And that pattern continues on for whoever knows how many times. So in the end I have a directory C:/Apache/www-root/images/bgs/ images/bgs/ images/bgs/ images/bgs/ images/bgs/ images/bgs/ images/bgs/ images/bgs/ images/bgs/ images/bgs/images (minus the spaces) and that is DEFINITELY not what I want to ever happen. So to finally get to the actual question: How can I make sure that $input{'copy_to'} is not a subdirectory of $input{'directory'}?? Here is some more code. I believe that I know where the missing code has to go. It is colored in red. This is what I use to display a list of options to the web user of which directories s/he can copy to:
So what code has to go in that red if statement (or maybe somewhere in that find sub) to make sure that $input{'copy_to'} is not a subdirectory of $input{'directory'}??
Let me sum this up in one sentence: Sorry for all the head scratching and confusion with this question. That was hard to describe... Edit Petruchio Fri Mar 15 06:46:11 UTC 2002 - Fixed typo in title on author's behalf Edit by tye as long path string made page render very wide in some browsers
Back to
Seekers of Perl Wisdom
|
|