2

I'm using the following function, to find files with specific file extensions within a given folder and all subfolders:

function FindVideoFiles($startfolder,$specificextensions){
        $it = new RecursiveDirectoryIterator($startfolder);
        foreach( new RecursiveIteratorIterator($it) as $file) {
            if (in_array(strtoupper(substr($file, strrpos($file, '.') + 1)), $specificextensions)) {
                $files[]=array('nomedapasta'=>pathinfo($file,PATHINFO_DIRNAME));
            }
        }
        return $files;
}

$specificextensions is an array with avi,mkv and mp4 as values.

$startfolder is a string with /mnt/HD1_4TB/refazer/A View to a Kill as value.

When I try to run the function, it throws me an error saying: failed to open dir: No such file or directory.

The weirdest thing is, if I change the $starfolder variable to /mnt/HD1_4TB/refazer, the function works and return the files inside the folder "A View to a Kill" (even with spaces in folder name). If i rename the folder "A View to a Kill" to "AViewtoaKill" and change the $startfolder variable to /mnt/HD1_4TB/refazer/AViewtoaKill, the function also work..... so..... I think that my problem is the spaces in the folder name. Can someone help me on how I can solve this problem without removing the spaces in the folder name?

Thanks

pppery
  • 3,731
  • 22
  • 33
  • 46
  • Great movie, great music – dazed-and-confused Feb 12 '21 at 21:38
  • 3
    I would recommend looking at `A View to a Kill` and checking if it does indeed have the byte-sequences for spaces exactly that you think it does. For instance, maybe it has a hidden trailing space or other space-like character? Start in `/mnt/HD1_4TB/refazer` and just list the contents as [hex or bytes](https://stackoverflow.com/a/11466734/231316). – Chris Haas Feb 12 '21 at 22:54
  • @ChrisHaas by following your tip, i got : /mnt/HD1_4TB/refazer/A View to a Kill array (size=41) ..... 22 => int 65 23 => int 194 24 => int 160 25 => int 86 26 => int 105 27 => int 101 28 => int 119 29 => int 194 30 => int 160 31 => int 116 32 => int 111 33 => int 194 34 => int 160 35 => int 97 36 => int 194 37 => int 160 38 => int 75 39 => int 105 40 => int 108 41 => int 108 shouldn't the space character be "32" ? but in here it shows as "194" "160"... i'm starting to think that my problem is not php related, but debian related. – FreddyKrueger Feb 13 '21 at 01:01
  • @ChrisHaas .... thanks for your thoughts. Do you have any idea on how i could solve my problem ? – FreddyKrueger Feb 13 '21 at 01:08
  • Found it .... : $startfolder=str_replace(chr(194) . chr(160), chr(32), $startfolder); – FreddyKrueger Feb 13 '21 at 21:14
  • @ChrisHaas.... i would like to accept your answer as correct....but i can't :( – FreddyKrueger Feb 13 '21 at 21:17
  • @FreddyKrueger, I'm not at a spot where I can post an answer easily. If you want to just post what you did as an answer and accept it, I'm fine with that. – Chris Haas Feb 13 '21 at 22:21

1 Answers1

-1

Use Explode and Implode function to do a successful search, example get the folder name from directory and remove all the spaces from it's name and compare, use folders name at backend without spaces. Try this.

$fileNameWithSpace = "A View to a Kill";
$fileWithoutSpace = (explode(" ",$fileNameWithSpace ));
echo implode("",$strWithoutSpace); //AViewtoaKill
SAW Kk
  • 74
  • 9