Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am building my own file management system with the ideas below:

File Management System ----------------------- Admin file upload manager > Allow any files to be uploaded > Upload form has pulldown of registered users (pulldown associated wi +th a database) >> One file can be uploaded at a time and will be uploaded to the user +'s folder as chosen above ^ Member file manager > Login which redirects to specific folder (cookie authentication) > They are brought to another script which scans all files in their di +rectory and: >> Puts them all into a hash/array by given file type >> Records the file name, the date it was uploaded and file size >> The script prints these out on the screen in order by given file ty +pe and date (newest date on top). These will be links to the particu +lar file so they can download any file they want. Example: It would print all images on top, then say zip files, then text, etc. + Each category would be setup in chronological order.
Now, I can do almost all of this with scripts I already wrote. I have a file upload script I've written along with many login scripts.

The question I have is, how do I do the file reading so it slurps up all file names and file data in their folder?

Thanks.

Replies are listed 'Best First'.
Re: file management system
by Zaxo (Archbishop) on Oct 11, 2004 at 20:17 UTC

    You have lots of choices. See File::Find or glob or opendir.

    To be really accurate about file types, try File::MMagic.

    You may find that it's worthwhile to cook up a makefile which generates a static index page. You'd run make in the directory as part of the cleanup in the admin's upload script.

    After Compline,
    Zaxo

      Thanks for the suggestion. I looked through File::Find and it doesn't seem to provide any practical code, atleast not relevent to what I'm trying to do. It has a few snippets but nothing to the degree of what I'm trying to do (I've also searched other sites on it as well).

      Can you or anyone else show how to do it with opendir so I don't have to grab another module to do this? All I really need to do is read all the files and group them in their own separate arrays or hashes with their file information.

      Thanks everyone.

Re: file management system
by cLive ;-) (Prior) on Oct 11, 2004 at 22:00 UTC
    opendir(DIR,'/path/to/dir') || die $!; # assuming all files or dirs contain at least one # word character ( ie, lose . and .. ) my @dir_list = grep /\w/, readdir(DIR); closedir(DIR); my @files = (); my @dirs = (); for (@dir_list) { if (-d "/path/to/dir/$_") { push @dirs,$_; } else { push @files, $_; } }
    cLive ;-)

    ps - if you want the file sizes and other file information, you probably want to look at stat