views:

100

answers:

4

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?

A: 

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

Rob
i need to find the file first in the directory.For example: I have the file name: iamfile01.I need to find it first...I know it is on hard drive X: but no idea in which directory it could be in.
Kel
+1  A: 

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.

oedo
+1  A: 

http://stackoverflow.com/search?q=php+recursive+file

Col. Shrapnel
It can't find network drives:Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(X:\apps)... failed to open dir: No such file or directory'
Kel
A: 

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);
soulmerge