CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Getting First File Name in Folder

Print topic Send  topic

Author Message
DonP
Posted: 02/12/2008, 9:51 AM

On a grid, I have a label that grabs the names of the image thumbnails
in the folder, the shows them as images. However, I also want to grab
the name of only the first non-thumbnail file by itself before the rest.
The first two files are . and .. rather than image names so I am not
sure how to do it without getting the rest. All I am able to get is the
dot when using:

$handle2 = opendir($directory."/Large");
$FirstFile = readdir($handle2);

Can anyone help? Thanks.

Don (DonP)
DonB
Posted: 02/12/2008, 10:12 AM

You just keep repeating the readdir() in a loop and it returns the next file
until there are no more files found.

--
DonB



"DonP" <forum@pc-homepage.com> wrote in message
news:fosmbb$9g8$1@news.codecharge.com...
> On a grid, I have a label that grabs the names of the image thumbnails in
> the folder, the shows them as images. However, I also want to grab the
> name of only the first non-thumbnail file by itself before the rest. The
> first two files are . and .. rather than image names so I am not sure how
> to do it without getting the rest. All I am able to get is the dot when
> using:
>
> $handle2 = opendir($directory."/Large");
> $FirstFile = readdir($handle2);
> Can anyone help? Thanks.
>
> Don (DonP)

DonP
Posted: 02/12/2008, 10:28 AM

Thanks, Don. Since I have been using CodeCharge Studio almost
exclusively for years, it has me so spoiled that I am not even sure
how to create manual loops anymore. I know how to get all the files
but I am unsure if how to get only the one I want, which is the first
one after the two dot files. Can you show me some code? Thanks again.

Don (DonP)

DonB wrote:
> You just keep repeating the readdir() in a loop and it returns the next file
> until there are no more files found.
>
DonB
Posted: 02/12/2008, 10:58 AM

while ($FirstFile = readdir($handle2)) {
if (($FirstFile != '..') && ($FirstFile != '.')); break;
}

--
DonB



"DonP" <forum@pc-homepage.com> wrote in message
news:fosogt$auk$1@news.codecharge.com...
> Thanks, Don. Since I have been using CodeCharge Studio almost exclusively
> for years, it has me so spoiled that I am not even sure how to create
> manual loops anymore. I know how to get all the files but I am unsure if
> how to get only the one I want, which is the first one after the two dot
> files. Can you show me some code? Thanks again.
>
> Don (DonP)
>
> DonB wrote:
>> You just keep repeating the readdir() in a loop and it returns the next
>> file until there are no more files found.
>>

DonP
Posted: 02/12/2008, 12:47 PM

Thanks Don, but I seem to be missing something here as it is still
giving only the dot instead of a file name. Also, rather than saying
what not to get, how can I make it get only jpg, gif and png files? That
would be more direct and to the point in case the folder contains
anything else. I am doing that already with the thumbnails but I can't
figure out how to apply it here.

This is what I have for the thumbnails:

while (false !== ($file = readdir($handle))) {
$pieces = explode(".", $file);
$FileType = $pieces[count($pieces) -1];
if ($FileType == "jpg" || $FileType == "gif" || $FileType == "png") {
$output[] = '<img src="'.$directory.'/Reduced/'.$file.'">';
}
}

This was created as part of a function, the many HTML lines of which are
output to a label using

return join("\n",$output);

Don (DonP)

DonB wrote:
> while ($FirstFile = readdir($handle2)) {
> if (($FirstFile != '..') && ($FirstFile != '.')); break;
> }
>
DonP
Posted: 02/12/2008, 4:21 PM

This did the trick:

while ($FirstFile = readdir($handle2)) {
$pieces2 = explode(".", $FirstFile);
$FileTypeLarge = $pieces2[count($pieces2) -1];
if ($FileTypeLarge == "jpg" || $FileTypeLarge == "gif" ||
$FileTypeLarge == "png") {
break;
}
}

Don (DonP)

DonB wrote:
> while ($FirstFile = readdir($handle2)) {
> if (($FirstFile != '..') && ($FirstFile != '.')); break;
> }
>

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.