473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

first file from every subfolder!

How do I get a list of the first file of every subfolder?
This is what i have so far
<?php
function getfirstImage($dirname)
{
global $imageName;
$ext = array("jpg", "png", "jpeg", "gif", "JPG", "PNG", "GIF",
"JPEG");
if($handle = opendir($dirname))
{
while(false!== ($file = readdir($handle)))
{
if(strstr($file, "." . $ext[$i])!= '.' && strstr($file, "." .
$ext[$i])!= '..')
{
break;
}
}
$imageName = $file;
closedir($handle);
}
return($imageName);
}

echo getfirstImage('../galleri/galleri/diverse/');
?>

$getfirstImage(../galleri/galleri/)
Aug 18 '08 #1
4 1281
On Aug 18, 12:11*pm, Effix <Morteneist...@gmail.comwrote:
How do I get a list of the first file of every subfolder?
To do this for every subfolder, you would make a readdir loop which
determines whether the file is a directory (is_dir) and call
getfirstImage() for each directory.

function getfirstImage($dirname)
{
$imageName = false;
$ext = array("jpg", "png", "jpeg", "gif", "JPG", "PNG", "GIF",
"JPEG");
if($handle = opendir($dirname))
{
while(false !== ($file = readdir($handle)))
{
$lastdot = strrpos($file, '.');
$extension = substr($file, $lastdot + 1);
if ($file[0] != '.' && in_array($extension,
$ext))
{
break;
}
}

$imageName = $file;
closedir($handle);

}
return($imageName);
}
Aug 18 '08 #2
Effix wrote:
How do I get a list of the first file of every subfolder?
This is what i have so far
<?php
function getfirstImage($dirname)
{
global $imageName;
$ext = array("jpg", "png", "jpeg", "gif", "JPG", "PNG", "GIF",
"JPEG");
if($handle = opendir($dirname))
{
while(false!== ($file = readdir($handle)))
{
if(strstr($file, "." . $ext[$i])!= '.' && strstr($file, "." .
$ext[$i])!= '..')
{
break;
}
}
$imageName = $file;
closedir($handle);
}
return($imageName);
}

echo getfirstImage('../galleri/galleri/diverse/');
?>

$getfirstImage(../galleri/galleri/)
Where are you setting/incrementing $i?
Why aren't you just doing
if ($file != '.' && $file != '..')
if those are the two you want to bypass. If you THEN want to check that
it is one of your extension types, then do a foreach on $ext.
Aug 18 '08 #3
sheldonlg wrote:
Effix wrote:
>How do I get a list of the first file of every subfolder?
This is what i have so far
<?php
function getfirstImage($dirname)
{
global $imageName;
$ext = array("jpg", "png", "jpeg", "gif", "JPG", "PNG", "GIF",
"JPEG");
if($handle = opendir($dirname))
{
while(false!== ($file = readdir($handle)))
{
if(strstr($file, "." . $ext[$i])!= '.' && strstr($file, "." .
$ext[$i])!= '..')
{
break;
}
}
$imageName = $file;
closedir($handle);
}
return($imageName);
}

echo getfirstImage('../galleri/galleri/diverse/');
?>

$getfirstImage(../galleri/galleri/)

Where are you setting/incrementing $i?
Why aren't you just doing
if ($file != '.' && $file != '..')
if those are the two you want to bypass. If you THEN want to check that
it is one of your extension types, then do a foreach on $ext.

....also, what happens if a file is named foo.JpG ??
Aug 18 '08 #4
On 18 Aug, 11:11, Effix <Morteneist...@gmail.comwrote:
How do I get a list of the first file of every subfolder?
How are you defining "first"?
Aug 18 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jake | last post by:
I know how to copy files from one location to another but how would I go about copying a file from one directory into serveral - or actually all subdirectories in a single action? Some kind of...
1
by: Wanda | last post by:
Hi, I tried to open a file in aspnet: FileOpen(intFile, "\\MachineName\path\subfolder\filename", OpenMode.Output) However, I received the following error message:...
9
by: Paul | last post by:
I'm trying to make get my app to delete all the files in a specified folder and all the files within the folders of the specified folder. e.g. Folder 1 contains three files (File1, File2, File3)...
5
by: Justin Fancy | last post by:
Hi Everyone, I am developing a file aging program that will eventually report on every folder that is in the root directory. I have a list of requested years, and counters set up to count every...
2
by: hkhella | last post by:
I am a novice and need lots of help - using VB 2005. I receive many files daily from an automated center. These files are autmatically downloaded into a subfolder on my computer. I need to move...
6
by: Thanh-Nhan Le | last post by:
Hello, I have an ASP application on IIS server: http://localhost/myApp I use ASP and a my own VB activex DLL to create a pdf file and write this file to a subfolder of the Application folder:...
5
by: woolls01 | last post by:
I am using the following code Sub Ck() Dim strStartPath As String strStartPath = "d:\workpack\rra" ListFolder strStartPath End Sub
0
by: deve8ore | last post by:
Hi.... I'm getting closer to understanding the wildcard function in VBA, however we have a vendor that will supply us many files, and unfortunately will place them in different folders with no...
6
by: deve8ore | last post by:
Hello, We have a vendor that will supply us many files, and unfortunately will place them in different folders with no uniformity (within Windows Explorer). I'd like to have the capability to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.