Move File starting with A-D and E-G and H-L and M-P and Q-T and U-W and X-Z
I have millions of file in a Folder its difficult to read with script so i need to store file in separate folder. just like
Move File to A-D and E-G and H-L and M-P and Q-T and U-W and X-Z with there starting character..
I try to use FTP but million so file did not show in directory correctly (took very long time to display and for moving, some time FTP stuck), also try cpanel etc. but no luck.
if there is a solution with PHP script ple开发者_开发技巧ase let me know, its help me alot.
Well, you could use DirectoryIterator
and move the files based on the filename. I'd still rather recommend a more direct approach with SSH or similar (there are things PHP wasn't meant to do - like non-website things); this approach is Remote Client --request--> Web Server --access--> File System.
Other than that, something like
$dirname = dirname(__FILE__);
$iterator = new DirectoryIterator($dirname);
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile() && $fileinfo->isWritable()) {
$fname = $fileinfo->getFilename();
rename($dirname. DIRECTORY_SEPARATOR .$fname, $dirname. DIRECTORY_SEPARATOR .ucfirst(substr($fname, 0, 1)). DIRECTORY_SEPARATOR .$fname);
}
}
Should move the files into a subdirectory with the same letter as the first character in the filename. If you want to move based on category groups of characters, just put the rename()
call into a switch
statement.
精彩评论