Sorry if the title is confusing... I can't quite figure out how to word what I am trying to do...
I have written a script that checks a network share to see if a file exists. If it does, the script uses the pre-processed file. If not, file is processed on the spot. It works well except for a recent developement. Here is a brief example of what is going on:
An unrelated piece of software converts files of one type (file 'A') into files of another (file 'B'). Then the original file ('A') gets treated again by a secondary process (file 'C') which sits and waits for the PHP script to come deal with it. File 'A' is then thrown out, leaving only Files 'B' and 'C' behind. Everything works well as long as the only thing that changes over the various files is their extension (.eps, .rtl & .tif respectively).
Example:
File A: 12345_File01.eps
File B: 12345_File01.rtl
File C: 12345_File01.tif
However, occasionally file 'B' has some info appended to it name.
Example:
File A: 12345_File01.eps
File B: 12345_File01_#123.rtl
File C: 12345_File01.tif
The script creates a list of filenames by looking in 'Directory B' and then stripping off their extensions. It then looks in 'Directory C' to see if it can find a matching file (12345_File01). As long as filename 'B' hasn't been altered, it works great. When filename 'B' has been changed, the matching file 'C' can't be found because it hasn't been similarly altered. I can't control the renaming of file 'B' nor can I alter the name of file 'C' to match. In addition, the additional information appended to 'B' changes frequently, as well as what exactly is added. Sometimes it's just a number, other times it's text or any combination of the two.
Here is a small section of the script so you can see what's going on:
// Check to see if converted file already exists
if (!file_exists($file_c)) {
// Check to see if there is a source tif to be converted
if (file_exists($file_b)) {
// Image Magick follows...
$command = "convert \"$file_b\" -quality 85 \"$file_c\"";
system( $command );
} else {
die("Woah! I can't find the preview file for {$_GET['file']}.");
}
}
What I need to be able to do is, given either:
"12345_File01"
OR
"12345_File01_#123"
OR
"12345_File01_Info_#1234"
...to look in a directory and recognize that the file "12345_File01" is the one it is looking for.
Basically, I'm trying to match everything BEFORE the extension of File 'C' (12345_File01 in this case) but given the filename from 'B'
Does this make sense? Is it possible?