I merely have the file name, without extension (.txt, .eps, etc.) The directory has several subfolders. So, the file could be anywhere.
How can I seek the filename, without the extension, and copy it to different directory?
http://www.pgregg.com/projects/php/preg_find/preg_find.php.txt seems to be exactly what you need, to find the file. then just use the normal php copy() command http://php.net/manual/en/function.copy.php to copy it.
have a look at this http://php.net/manual/en/function.copy.php
as for seeking filenames, could use a database to log where the files are? and use that log to find your files
I found that scandir() is the fastest method for such operations:
function findRecursive($folder, $file) { foreach (scandir($folder) as $filename) { $path = $folder . '/' . $filename; # $filename starts with desired string if (strpos($filename, $file) === 0) { return $path; } # search sub-directories if (is_dir($path)) { $result = findRecursive($path); if ($result !== NULL) { return $result; } } } } For copying the file, you can use copy():
copy(findRecursive($folder, $partOfFilename), $targetFile);
text.txtbut the program found and copiedtext.doc?