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

Backtracking through a directory.

Win
I was wondering if there was a way to backtrack through a directory.
Let's say that we "readdir'd" our way through the directory to the end
and now would like to back up 3 files to read the third from the last.

Is there an easy way to do this or would I have to find the total
number of directory entries and then calculate exactly how many reads
it takes before getting to the desired location?

Any input would be appreciated.

<?php
$dir = '../zone16/misc';
if ( is_dir($dir) && ($dh = opendir($dir)) )
{
while ( ($file = readdir($dh)) !== false )
{
print $file.'<br>';
}
if ( ($file = readdir($dh)) == false )
{
[!!!back up 3 files and read the third to last file!!!]
}
}
?>

Jul 17 '05 #1
3 1601
Win wrote:
I was wondering if there was a way to backtrack through a directory.
Let's say that we "readdir'd" our way through the directory to the end
and now would like to back up 3 files to read the third from the last.

Is there an easy way to do this or would I have to find the total
number of directory entries and then calculate exactly how many reads
it takes before getting to the desired location?


Either that, or store the result of the successive readdir()s in an
array.

Jul 17 '05 #2
Win
Thanks for the input, Oli. :-)

Jul 17 '05 #3
The easiest way to work with file listing is glob().

http://www.php.net/glob/

Jul 17 '05 #4

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

Similar topics

1
by: Steven Spear | last post by:
Hi. I am trying to perform backtracking with this search function. Something is going wrong when I enter 2 at the command line. Entering 1 at the command line seems to work fine. I notice that...
3
by: shoo | last post by:
I am writing a program on Backtracking recursion in search of the gold. but I don't know how to start my search at location (1,1), which should be Island in a empty space character.. Here is...
6
by: Talin | last post by:
I've been using generators to implement backtracking search for a while now. Unfortunately, my code is large and complex enough (doing unification on math expressions) that its hard to post a...
6
by: dave | last post by:
I really have 2 questions regarding the following xml snippet. The xml is a directory representation. <?xml version="1.0" standalone="yes"?> <FileSystem> <Row> <ID>1</ID> <Name>Root</Name>...
2
by: ChuckB | last post by:
Ok, I'm working on this program to do recursive backtracking, however it's not working for all cases. Any help would be apprietiated. (all 4 should be true, but 168 is coming up false) Heres the...
12
by: NOO Recursion | last post by:
Hi everyone! I am trying to write a program that will search a 12x12 for a thing called a "blob". A blob in the grid is made up of asterisks. A blob contains at least one asterisk. If an...
1
by: ROMANIA | last post by:
Dear mr. enginer Please help me to rezolv this prolem. We have some arrays: A1 1 2 3 4 5 6 14 17 23 24 27 33 A2 7 11 13 17 19 20 25 A3 23 25 26...
6
by: falconsx23 | last post by:
I am trying to write a code for a Phone Directory program. This program is suppose to allow the user to enter a name or directory and then program can either add, save or even delete an entry. Also...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.