Jump to content

Recommended Posts

Hello everyone who's reading this! :) I have a script that counts how many files I have in a specific folder, but I recently added index.html files with a redirect script in them to all of my folders and now I don't want my script to count that index.html file. So, is it possible to make it count all files except for 1? This is the script I'm using:

 

<?php

$path_layouts = opendir("/home/***/public_html/graphics/layouts");

while ($directory_layouts = readdir($path_layouts))
{
if ($directory_layouts != "." && $directory_layouts != "..")
{
$counter_layouts++;
}
}

echo $counter_layouts;

closedir($path_layouts);

?>

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/38658-counting-files-in-a-folder/
Share on other sites

<?php

$path_layouts = opendir("/home/***/public_html/graphics/layouts");

while ($directory_layouts = readdir($path_layouts))
{
if ($directory_layouts != "." && $directory_layouts != ".." &&  $directory_layouts != "index.html")
{
$counter_layouts++;
}
}

echo $counter_layouts;
closedir($path_layouts);

?>

Why not just do this:

 

<?php

 

$path_layouts = opendir("/home/***/public_html/graphics/layouts");

 

while ($directory_layouts = readdir($path_layouts))

{

if ($directory_layouts != "." && $directory_layouts != ".." || $directory_layouts != "index.html")

{

$counter_layouts++;

}

}

 

echo $counter_layouts;

 

closedir($path_layouts);

 

?>

 

If you have several files that you dont want counted put them in an array...

No problem.  One thought, I think you meant

&& $directory_layouts != "index.html"

 

as

 

|| $directory_layouts != "index.html")

 

will cause the conditional to return true if $directory_layouts != "index.php" even if $directory_layouts == ".." or ".".

 

I think it was just a mistype, but I thought I'd point it out so no one gets confused.

 

Best,

 

Patrick

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.