Clear questions and runnable code
get the best and fastest answer
Search and Copy a filepathby mikasue (Friar)
|on Oct 31, 2006 at 21:59 UTC||Need Help??|
mikasue has asked for the
wisdom of the Perl Monks concerning the following question:
I seek your advice and help on the following situation.
I have a program that allows the user to open an image file from a File Open box in Windows. The problem is my program expects the file to be in my \Images folder. If the user opens a file in the c:\windows directory my program fails becuase it is looking for the image in the \Images folder.
So, I can either copy the file over as soon as the user selects it or I can have my program read from any directory instead of just my \Images folder.
Which method is better?
My first problem is, I do not know how to implement either option.
So, I have researched ways to copy the file to my Images folder immediately after the user selects it and found File::Copy. My problem here is, I do not know how to compare the filepaths. I thought maybe s/// but that replaces the pathname. I need to compare them or really search for the substring \MYPROGRAM\IMAGES in the path selected by the user and then if they do not match copy file #1 to file #2.
I think I can use Find::File to search my directory for the basename($imgfile) filename. If it is not there I can use File::Copy to copy it there.
What do you monks advice?