Jump to content

jaesun

Members
  • Posts

    10
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

jaesun's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. When I mention that notepad++ shows it fine when changing the encoding, I am referring to café, not the characters ğ/ě. Notepad is showing ğ/ě as g/e as if php/iterator has replaced it with the letters g/e. Even if I change the encoding to be correct, it still shows as g/e And I am not worried about the display as in the end, I am not using it for display (more for backend stuff). The bigger problem for me is that I am not even able to reference the file or know that the file is in the directory. When I run the function, if the directory contains 5 files, but one file contains the g/e, it returns it to me with an array of 4 files. $fileinfo->isFile() returns false, and $fileinfo->isDir() returns false. So the rest of the code after the function call acts as if the file does not exist whatsoever. So a directory with café.txt, test1.txt, Dağ_Piě.txt ... the function returns an array(café.txt, test1.txt) The iterator that grabs all the files is able to pick up the file, just returns false on checking if its a file or directory. if I uncomment the echo in the else{} stm, it will display the filename, but the letters ğ/ě replaced with g/e, again, as if the 2 letters were replaced by e/g and $fileinfo->isFile()/$fileinfo->isDir() returns false no matter what ... which leads me to believe that no matter what I change the encoding on display, it won't matter what encoding I use to display.
  2. I am just displaying it to the browser to test it. I have tried writing the results of the contents of the directory to a file, but still, comes back as g/e respectively. While the other filenames like in cafe will show in the file fine (and I can change the encoding while viewing in notepad++ and see it). But its like the g/e are just that, the letters g/e itself, as if the iterator/scandir functions returned it to me as such.
  3. PHP Version: 7.0.10 Windows So I have this function, that grabs all the files within a directory. function getDirectoryListing($folder) { $aryListing = array(); $dir = new RecursiveDirectoryIterator($folder, FilesystemIterator::SKIP_DOTS); // Flatten the recursive iterator, folders come before their files $it = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST); foreach ($it as $fileinfo) { if ($fileinfo->isFile()) { $f = array(); $f['file'] = $fileinfo->getFilename(); $f['dir'] = "\\" . $it->getSubPath(); $f['pathfile'] = $it->getSubPathName(); $f['size'] = $fileinfo->getSize(); $f['size_human'] = bytesToHuman($fileinfo->getSize()); $f['time_mod'] = $fileinfo->getMTime(); $f['time_mod_full'] = date('F j, Y, g:i a', $fileinfo->getMTime()); $aryListing[] = $f; } elseif ($fileinfo->isDir()) { //print($fileinfo->__toString() . PHP_EOL); // directory } else { // echo $fileinfo->getFilename(); // not file or directory? } } return $aryListing; } But with certain accented characters such as ğ or ě (https://en.wikipedia.org/wiki/Ğ and https://en.wikipedia.org/wiki/Ě respectively), it returns as the letters g and e instead of the accented characters. So a file like Dağ_Piě.txt will return as Dag_Pie.txt So in the above code, it is not returned in the array as it is skipped over since Dag_Pie.txt is not a file (and is not a directory either). This doesn't happen with all files with accented characters. Files such as café.txt are fine. Sure, I can rename all the files manually I find on the server, but I prefer a solution that can read the filenames correctly (and then rename them accordingly if I choose to with the script). I don't want to go through every single filename ever so often. scandir returns the same thing. Any help would be appreciated
  4. The folder structure was: H:\Videos\_Sort\Looney.Tunes.1956.TV\102756 Wideo Wabbit MM CN.avi So the first time I grab a list of contents, I was just grabbing the parent folders (Looney.Tunes.1956.TV). Then from there, I grabbed the video files within that folder. I am not defending the code, it was late night and something i just kinda copied and pasted for a one time use script (I had like 20 folders of files to rename and I got tired of manually doing them myself). I know I can change the code easily and not bother going through the list with readdir() and rename during that process. and that I should just grab the video list first, then go about the file renames which would eliminate any issues. I was just intrigued by the behavior of readdir() itself and why it would do that after only a certain number of files was in the directory.
  5. I quickly created this script to rename a bunch of files, that was renaming a bunch of files based on the season/episode. It grabs the directory listing, check the filename and determine which episode number, and rename the file into the same directory. But sometimes, it would recheck the newly renamed files, essentially twice. It seemed to happen when the directory had 25 or more files. code: $sort_folder = scandir('H:\\Videos\\_Sort\\', 1); array_pop($sort_folder); // remove . array_pop($sort_folder); // remove .. foreach($sort_folder as $folder) { $n = explode('.', $folder); $year = str_replace('S', '', $n[2]); $episodes = $seasons[$year]['episodes']; // array that holds all episode titles, episode number for the season $numFiles = 0; if ($handle = opendir('H:\\Videos\\_Sort\\' . $folder)) { while (false !== ($fileName = readdir($handle))) { if ($fileName == '.' || $fileName == '..') continue; echo "\n$fileName:\n"; foreach ($episodes as $e) { if (strripos($fileName, $e['title']) !== false) { $numFiles++; echo $fileName . ' => ' . 'Looney.Tunes.s' . $year . '.e' . sprintf('%02d', $e['epnum']) . '.' . $fileName . "\n"; rename('H:\\Videos\\_Sort\\' . $folder . '\\' . $fileName, 'H:\\Videos\\_Sort\\' . $folder . '\\' . 'Looney.Tunes.s' . $year . '.e' . sprintf('%02d', $e['epnum']) . '.' . $fileName); break; } } } closedir($handle); if ($numFiles != count($episodes)) { echo 'Some Files were not renamed'; } } } Some example output: ...Normal Expected renames 102756 Wideo Wabbit MM CN.avi: 102756 Wideo Wabbit MM CN.avi => Looney.Tunes.s1956.e25.102756 Wideo Wabbit MM CN.avi Looney.Tunes.s1956.e01.011456 Bugs Bonnets MM.mpg: Looney.Tunes.s1956.e01.011456 Bugs Bonnets MM.mpg => Looney.Tunes.s1956.e01.Looney.Tunes.s1956.e01.011456 Bugs Bonnets MM.mpg ...Goes to rename all the files over again one more time If I left only 24 files, it would just rename it all once, as expected. Add a 25th file to rename, and it would rename them all twice over. I was thinking, well, it just grabs the next file in the resource handle, and since files are getting renamed, the newly renamed files will come after the old files are cycled through, since, in the resource (being that same directory), the pointer will point to the new file. But then wouldn't that happen regardless of how many files in the directory? even if there are 28 files, or 5 files. But it seems to only happen once I reach 25 files in the directory. I checked PHP docs, but saw nothing there that would hint at this behavior? Edit: Sorry for the bad title. Hit Submit rather than preview.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.