rgb192
asked on
scan another directory using windows os
I am using php for windows, not looking for linux answer
this works in same directory
how can I make this work for another directory
this works in same directory
<?php
$filesarray = array();
if ($handle = opendir('.')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && is_file($entry)) {
//echo "$entry<br />";
$filesarray[] = $entry;
}
}
closedir($handle);
}
print_r($filesarray);
?>
how can I make this work for another directory
<?php
$filesarray = array();
if ($handle = opendir('C:/gyb/')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && is_file($entry)) {
echo "$entry<br />";
$filesarray[] = $entry;
}
}
closedir($handle);
}
print_r($filesarray);
?>
I don't understand - your second piece of code looks like it should work, so what are you asking?
Try this, Ive removed the trailing slash
Use this:
Use this:
<?php
$filesarray = array();
if ($handle = opendir('C:\gyb')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && is_file($entry)) {
echo "$entry<br />";
$filesarray[] = $entry;
}
}
closedir($handle);
}
print_r($filesarray);
?>
ASKER
no output with these 3:
if ($handle = opendir('C:\gyb')) {
if ($handle = opendir('C:/gyb')) {
if ($handle = opendir('C:/gyb/')) {
parse error with the
'
if ($handle = opendir('C:\gyb\')) {
if ($handle = opendir('C:\gyb')) {
if ($handle = opendir('C:/gyb')) {
if ($handle = opendir('C:/gyb/')) {
parse error with the
'
if ($handle = opendir('C:\gyb\')) {
What's in that folder? Is there any files in there or just other folders?
ASKER
files and other folders
Try this:
<?php
$filesarray = array();
if(!is_readable('C:/gyb'))
{
echo "You don't have enough permissions to access this folder!";
die();
}
if ($handle = opendir('C:/gyb/')) {
echo "Opened the folder successfully!<br>\n";
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && is_file($entry)) {
echo "$entry<br />";
$filesarray[] = $entry;
}
}
closedir($handle);
}
else
{
echo "There was an error opening the folder!";
die();
}
print_r($filesarray);
?>
<?php
$filesarray = array();
if(!is_readable('C:/gyb'))
{
echo "You don't have enough permissions to access this folder!";
die();
}
if ($handle = opendir('C:/gyb/')) {
echo "Opened the folder successfully!<br>\n";
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && is_file($entry)) {
echo "$entry<br />";
$filesarray[] = $entry;
}
}
closedir($handle);
}
else
{
echo "There was an error opening the folder!";
die();
}
print_r($filesarray);
?>
ASKER
Opened the folder successfully!
Array ( )
I have tried with many folders
with and without the trailing
/
Array ( )
I have tried with many folders
with and without the trailing
/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
I have a related question because
I also want to read the folders and put the folders in a separate array
https://www.experts-exchange.com/questions/27996910/I-also-want-to-read-the-folders-and-put-the-folders-in-a-separate-array.html
I have a related question because
I also want to read the folders and put the folders in a separate array
https://www.experts-exchange.com/questions/27996910/I-also-want-to-read-the-folders-and-put-the-folders-in-a-separate-array.html