SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Listing all files in a directory that are not in DB

    Hi Guys, (long time not see )

    I am sure this is easy enough and I am just missing something, what I am trying to do is look in a folder on my server and see what folders are there, if the folder doesn't exist in the DB then I list it on my page. (Inserted into the DB in another place).

    I dont need a script written for me but some suggestions for the direction I need to go would be great. I have tried looking at file_exists but it doesnt do what I need it to as, as I wont know what the file is called.

    Thanks in advance
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    wooo! did you get the promotion?

    Right then...

    1/ do a query to get all the folder names out of the database and lump them into an array.

    2/ use a folder reading script such as glob() to get all the folders from the server.

    3/ manipulate and compare the 2 arrays using array_diff()

    4/ make a brew
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You need to pull a list from the DB then a list of the current file system and remove those that are in the DB.

    Code php:
    $DBa = array('a', 'b'); // Filled up with results from the DB
    $FSa = array('a','b','c','d','e','f','g'); // Filled up with results from filesystem
     
    $FSa = array_diff($FSa, $DBa);
     
    print_r($FSa);

    Edit: An I was just too darn slow >.> Stupid testing dragged me down...
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the info guys, the comparison isn't to much of a problem, just needed to know a function to get the contents of a dir. Is there a similar function to glob() that doesn't require an extention? I will be looking at folders and not files? Can that be done, if not Ill have to change my tactics I think.

    I am creating a module system and I want to list the ones that can be installed (not already). Each module is basically a folder with some files in, I was going to compare what was in the DB with what Folders were in a Dir, then list the ones that arent in the DB. I am making this harder than it needs to be?

    Off Topic:

    Long story about the promotion, and that job!
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    glob(*, GLOB_ONLYDIR
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  6. #6
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I just ran a small test, All my modules are name "something_Module", so I did this:

    PHP Code:
    <?php
    foreach (glob("*_Module") as $filename) {
        echo 
    "$filename size " filesize($filename) . "\n";
    }
    ?>
    Problem being it only returns the first folder, any ideas?
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Look at is_dir() and the functions inthe user notes. There are a few recursive functions that should help you.

    Off Topic:


    That sounds ominous about the Job..... PM me the gossip!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works like a charm. Thanks very much
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  9. #9
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I have a final question, Can I specify which folder to look in?
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  10. #10
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Which script did you go for? glob or is_dir()?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  11. #11
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I went for the glob() as you need to know all the files in a directory. Here is the code im using.

    foreach (glob('*_Manager', GLOB_ONLYDIR) as $filename) {

    I am running the Module_Manager.php page from this:
    "Includes/Modules/Module_Manager/Module_Manager.php"

    But I need to go back to the previous Dir to check all the folders, that make sense?
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  12. #12
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    probably just something like:

    foreach (glob('foldername/*_Manager', GLOB_ONLYDIR) as $filename) {
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  13. #13
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahem, well its late and uhm ... Thanks

    This did it:

    PHP Code:
    foreach (glob('Includes/Modules/*_Manager'GLOB_ONLYDIR) as $filename
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  14. #14
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    LOL yes it is a bit late in the day.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  15. #15
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    delphi the dolphin


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •