473,395 Members | 1,692 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,395 software developers and data experts.

First 10 files

Source
----------------------------------------
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
// Is it a valid extension?
if(!is_dir($file) && is_numeric(strpos($file, ".")))
{
if($this->_IsValidExtension($file))
$arrImages[] = $file;
}
}
closedir($dh);
}
}
How to change the code to have in $arrImages[] just the first 10
files from that directory, not all files (Order: DESC or ASC).

Thanks!

Mar 5 '07 #1
1 1052
Rik
sosoro <so*******@gmail.comwrote:
Source
----------------------------------------
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
// Is it a valid extension?
if(!is_dir($file) && is_numeric(strpos($file, ".")))
{
if($this->_IsValidExtension($file))
$arrImages[] = $file;
}
}
closedir($dh);
}
}
How to change the code to have in $arrImages[] just the first 10
files from that directory, not all files (Order: DESC or ASC).
$cur_dir = getcwd();
chdir($dir);
$arrImages = array_slice(glob(*.*),0,10);
//last 10: array_reverse(array_slice(glob(),-10,10);)
chdir($cur_dir);

Optionally with a somewhat better check then just '*.*'.
--
Rik Wasmus
Posted on Usenet: any site claiming this as original content or me as an
contributing member is wrong.
Ask Smart Questions: http://tinyurl.com/anel
Mar 5 '07 #2

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

Similar topics

16
by: John | last post by:
Hello. If I want to set up my first database and start using it in Dreamweaver what do I need to do? The book I'm working on has a CD with the database on. It is telling me to put it in the...
6
by: bart_nessux | last post by:
Hello, I have some Macbinary files on a PC. I want to recursively read these files and remove the first 128 bytes of the files if they contain the macbinary header info. I know how to read...
2
by: Jon Glazer | last post by:
When doing a getfolder() I want the first file in the resulting FILES collection. I don't want to do a for/next cuz the list may be very long. Just the first file is all. How do I do this? Doin...
16
by: TB | last post by:
Hi all: If you think that the following comments are absolute amateurish, then please bear with me, or simply skip this thread. A couple of months back I made the decision to initiate a...
2
by: MSDN | last post by:
Hello, I have the following code below that does not work for me because the directory has millions of files. foreach (string ofile in System.IO.Directory.GetFiles(strMyDir)) { ...
7
by: tshad | last post by:
I have a problem with a VS 2003 project. This project was designed and works fine in VS 2003. But trying to open the project I get the following error....
3
by: cs | last post by:
Hi, I'm new to C and would appreciate any feedback on the following program, asplit, which splits a file into 2 new files, putting a certain number of lines in the first file, and all the rest...
1
by: sorcrow | last post by:
Greetings, I'm new on the forum and relatively new to Python. What I need to do is verify that the first lines of a group of text files are identical. The files are all in the same directory....
1
by: x40 | last post by:
I try to learn python thru solving some interisting problem, found google trasure hunt, write first program ( but cant find whats wrong). # Unzip the archive, then process the resulting files to...
5
by: Just_a_fan | last post by:
I can get a dump. I can send it in to M$. I can inspect it but cannot get it in my hands so I can not post it here and get comments and/or answers. Can I get hold of that dump somewhere? Is it...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.