473,398 Members | 2,113 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,398 software developers and data experts.

building an array of files

Hello folks -

I'm working on a function to map a php project that's gotten a little
unwieldly. I'd like to have a reference of all files like the output
of the unix tree command, like this:
..
|-- index.php
| |-- menu.php
| |-- content.php
| |-- admin_page.php
| | |-- admin_function1.php.inc
| | |-- admin_function2.php.inc
| | |-- admin_function3.php.inc
| | `-- admin_subpage.php
| | |-- admin_subfunction1.php.inc
| | |-- admin_subfunction1.php.inc
| | `-- admin_subfunction1.php.inc
| `-- user_page.php
| |-- user_function1.php.inc
| |-- user_function2.php.inc
| |-- user_function3.php.inc
| `-- user_subpage.php
| |-- user_subfunction1.php.inc
| |-- user_subfunction1.php.inc
| `-- user_subfunction1.php.inc
|
|-- orphan_page.php
`-- deprecated_page.php

I have a function that can create such text output ( or close enough )
from an array structure like this:

Array (
[0] =./index.php
[1] =Array (
[0] =./clients.php
[1] =Array (
[0] =./login_function.inc
[1] =./client.php
[2] =./client_new.php
[3] =./client_edit.php
)
[2] =./inventory.php
[3] =Array (
[0] =./login_function.inc
[1] =./inventory_item_add.php
[2] =./inventory_item_remove.php
)

[4] =./daily_report.php
[5] =./weekly_report.php
[6] =./monthly_report.php
[7] =./catalog.php
[8] =Array (
[0] =./login_function.inc
[1] =./catalog_item_add.php
[2] =./catalog_item_remove.php
)
[9] =./orders.php
[10] =Array (
[0] =./login_function.inc
[1] =./view_order.php
[2] =./order_new.php
[3] =./order_edit.php
)
[11] =./invoices.php
[12] =Array (
[0] =./login_function.inc
[1] =./view_invoice.php
[2] =./invoice_new.php
[3] =./invoice_edit.php
[4] =./invoice_print.php
[5] =./invoice_email.php
)
)
[2] =./clients_old.php
[3] =./old_inventory.php

However, now I'm having a problem building the array of files!

Starting with a default root file, index.php, I can loop through each
file and find each .php or .inc file. Then I can create an array like

Array (
[0] =./index.php
[1] =Array (
[0] =./clients.php
[2] =./inventory.php
[4] =./daily_report.php
[5] =./weekly_report.php
[6] =./monthly_report.php
[7] =./catalog.php
[9] =./orders.php
[11] =./invoices.php
[2] =./clients_old.php
[3] =./old_inventory.php
)

Then, I need to go through each element and find out what files are
referenced in that file, and insert that array. So I would get:

Array (
[0] =./index.php
[1] =Array (
[0] =./clients.php
[1] =Array (
[0] =./login_function.inc
[1] =./client.php

However, I'm having problems getting started. What function can I use
to insert an array at a certain point?

Mar 26 '07 #1
2 1629
On Mar 26, 3:48 pm, lawp...@gmail.com wrote:
Hello folks -

I'm working on a function to map a php project that's gotten a little
unwieldly. I'd like to have a reference of all files like the output
of the unix tree command, like this:
.
|-- index.php
| |-- menu.php
| |-- content.php
| |-- admin_page.php
| | |-- admin_function1.php.inc
| | |-- admin_function2.php.inc
| | |-- admin_function3.php.inc
| | `-- admin_subpage.php
| | |-- admin_subfunction1.php.inc
| | |-- admin_subfunction1.php.inc
| | `-- admin_subfunction1.php.inc
| `-- user_page.php
| |-- user_function1.php.inc
| |-- user_function2.php.inc
| |-- user_function3.php.inc
| `-- user_subpage.php
| |-- user_subfunction1.php.inc
| |-- user_subfunction1.php.inc
| `-- user_subfunction1.php.inc
|
|-- orphan_page.php
`-- deprecated_page.php

I have a function that can create such text output ( or close enough )
from an array structure like this:

Array (
[0] =./index.php
[1] =Array (
[0] =./clients.php
[1] =Array (
[0] =./login_function.inc
[1] =./client.php
[2] =./client_new.php
[3] =./client_edit.php
)
[2] =./inventory.php
[3] =Array (
[0] =./login_function.inc
[1] =./inventory_item_add.php
[2] =./inventory_item_remove.php
)

[4] =./daily_report.php
[5] =./weekly_report.php
[6] =./monthly_report.php
[7] =./catalog.php
[8] =Array (
[0] =./login_function.inc
[1] =./catalog_item_add.php
[2] =./catalog_item_remove.php
)
[9] =./orders.php
[10] =Array (
[0] =./login_function.inc
[1] =./view_order.php
[2] =./order_new.php
[3] =./order_edit.php
)
[11] =./invoices.php
[12] =Array (
[0] =./login_function.inc
[1] =./view_invoice.php
[2] =./invoice_new.php
[3] =./invoice_edit.php
[4] =./invoice_print.php
[5] =./invoice_email.php
)
)
[2] =./clients_old.php
[3] =./old_inventory.php

However, now I'm having a problem building the array of files!

Starting with a default root file, index.php, I can loop through each
file and find each .php or .inc file. Then I can create an array like

Array (
[0] =./index.php
[1] =Array (
[0] =./clients.php
[2] =./inventory.php
[4] =./daily_report.php
[5] =./weekly_report.php
[6] =./monthly_report.php
[7] =./catalog.php
[9] =./orders.php
[11] =./invoices.php
[2] =./clients_old.php
[3] =./old_inventory.php
)

Then, I need to go through each element and find out what files are
referenced in that file, and insert that array. So I would get:

Array (
[0] =./index.php
[1] =Array (
[0] =./clients.php
[1] =Array (
[0] =./login_function.inc
[1] =./client.php

However, I'm having problems getting started. What function can I use
to insert an array at a certain point?
There isn't really a straightforward way to insert an element at some
arbitrary position in an array. You can split the array in two and
then stitch it back together with something in the middle.

Instead of processing your files level by level, why not do it
recursively? For instance, when your parse index.php, instead of
adding clients.php, then inventory.php, and then going back and
checking for their includes, add clients.php and check for his
includes. When that's done, add inventory.php and check for his
includes. That way you never need to insert the new array in the
middle of the parent -- it'll just happen in the right order the first
time.

Mar 26 '07 #2
ZeldorBlat wrote:
Instead of processing your files level by level, why not do it
recursively? For instance, when your parse index.php, instead of
adding clients.php, then inventory.php, and then going back and
checking for their includes, add clients.php and check for his
includes. When that's done, add inventory.php and check for his
includes. That way you never need to insert the new array in the
middle of the parent -- it'll just happen in the right order the first
time.
Or store the info as XML and use XPath.... The first bit of work would
be harder, but then all the lookups and stuff would be there for you.

And you really don't have to care where the stuff is in the tree - just
look it up every time and add child nodes.

--Yan
Mar 26 '07 #3

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

Similar topics

0
by: PatchFactory Support | last post by:
Description: Professional and easy-to-use patch building environment that can help you to create instant patch packages for software and file updating. Generated patch packages are small size...
4
by: brian | last post by:
Hello, I have spen hours trying to find information on dynamically building a table from an array. What I need: I have an array pulling file paths from a directory using a For Next Loop. F is...
6
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
1
by: lennyw | last post by:
Hi I'm trying to build XMLgawk (latest version 3.1.5 from sourceforge) and I'm getting some make errors. I'm using the tool availbale from Cygwin to do the build (gcc, bash, make). I was able...
6
by: Yi Xing | last post by:
Hi, I need to read specific lines of huge text files. Each time, I know exactly which line(s) I want to read. readlines() or readline() in a loop is just too slow. Since different lines have...
4
by: vedrandekovic | last post by:
Hi, I have already install Microsoft visual studio .NET 2003 and MinGw, when I try to build a extension: python my_extension_setup.py build ( or install ) , I get an error: LINK : fatal...
1
by: dileepd | last post by:
Hi Every one, Could you please let me know if you have any clue about following things. 1. Whether type bool acts like a kind of signed int type in g++ on solaris 9(a/c to my invetsigation it...
12
by: Ludwig | last post by:
Hi all, we are building our own class library framework, with stuff in it that can be used in various projects at various clients. Initially we had 4 assemblies with everything in it. Of...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.