Welcome Guest, Not a member yet? Register   Sign In
Automatic templating of text files within a directory (with caching)
#1

[eluser]BlkAngel[/eluser]
Greetings everyone!

I'm afraid that I require a little bit of assistance laying down the groundwork for a small personal project of mine. I'm basically trying to dive into PHP OOP, and I already did one small thing that works, so now I'm trying to make a little more ambitious project for myself.

Background: I have a lot of emails I want to save, and forgetting all the high-level Gmail stuff out there, what I have been doing for a while now is a simple copy/paste into text files in various subdirectories.

Synopsis:
I was thinking that should be possible to use Code Igniter for this task to build some experience using it (I tried playing with Zend Framework and for some reason the .htaccess stuff didn’t work out too well with calling the correct controller methods).

For the example, let’s say this is our directory structure:


Code:
/myTextFiles
  /sample1
  - a.txt
  - b.txt
  - c.txt
  /sample3
  - d.txt
  - e.txt
  - f.txt

What I would like to know is the best way to index and cache the contents of this directory, at least the filenames and hierarchy. For example, visiting the page responsible for showing the contents of the root directory (/myTextFiles in this case), I would expect to see:

sample1
sample2


Based on the directory names. Then following “sample1” link for example, I would get:

a
b
c


…allowing me to follow any of those links and see the contents of the corresponding .txt file in a templated page.

Problems I need to solve:
1) I don’t want to recurse down the directory tree every time a request comes in for /myTextFiles… if there are several hundred files in there, that is a lot of system calls just to display some links. Ideally, until something gets changed: a new file uploaded or some file deleted, I’d like to cache the directory structure in some way (DB perhaps). Does anyone know the groundwork of what might work best here, since this is somewhat uncharted territory for me at this moment? I have a feeling trees and parent/child relationships will be key here.

2) It would be easier to make it one directory level deep, but ideally I’d like to expand it for infinite recursion, so /myTextFiles -> DirectoryA -> DirectoryB ->… etc. as far as it needs to go (maybe an arbitrary limit designated by a constant or something).


I’d appreciate any suggestions or advice any of you might offer.


Messages In This Thread
Automatic templating of text files within a directory (with caching) - by El Forum - 07-09-2007, 12:20 PM



Theme © iAndrew 2016 - Forum software by © MyBB