Question

My code:

if ($d = opendir('.')) {
       while (($file = readdir($d)) !== false) {
            if ( $file != "."  && $file != ".." ){
                echo "filename: $file \n";
                $files[]=$file;
            }
       }
    closedir($d);
}

outputs:

filename: audio_files
filename: backup_files
filename: compressed_files
filename: database_files
filename: data_files
filename: developer_files
filename: disk_image_files
filename: executable_files
filename: font_files
filename: genstats.php
filename: raster_image_files
filename: spreadsheet_files
filename: text_files
filename: text_filesdesktop__dup.ini
filename: video_files
filename: web_files

whereas text_filesdesktop__dup.ini doesn't even exist.

C:\Users\Steve\Desktop\Files>del text_filesdesktop__dup.ini
Could Not Find C:\Users\Steve\Desktop\Files\text_filesdesktop__dup.ini

I have tried using scandir(), deleting the file and recreating it, etc, to no avail. I simply can't get that .ini file to go away.

Was it helpful?

Solution

might be you are having hidden files in your directory

what platform are your using , WiNDOWS OR Linux ,

If you just want to exclude files starting with a dot, ".",

try this:

$files = readdir('/path/to/folder');
$files = array_filter($files, create_function('$a','return ($a[0]!=".");'));

the above function only returs the files , chich are not starting with .

but on windows hidden files works differently , i dont know how to play with it .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top