Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Welcome to the Monastery
 
PerlMonks  

List Contents of Windows Directory Folder

by mua (Initiate)
on Dec 04, 2012 at 01:15 UTC ( #1006976=perlquestion: print w/ replies, xml ) Need Help??
mua has asked for the wisdom of the Perl Monks concerning the following question:

I've looked and looked but to no avail. I am hoping someone can give me the right solution path to my problem--I pray to the Perlmonks. I need a script to list a Windows directory folder with the following labels to be saved in a text file and, in the future, in a spreadsheet format: FileName Date Modified Type Size Somefilename 12/3/2012 5:10 PM SomeType SomeSize Anotherfilename 12/3/2012 5:11 PM AnotherTyp Size When more files are added to this folder, I need to append to the current text file. I am using ActiveState Perl in Windows 7 64 Bit. I have found scripts to list files in folders but it only lists the filenames. Thank you.

Comment on List Contents of Windows Directory Folder
Re: List Contents of Windows Directory Folder
by toolic (Chancellor) on Dec 04, 2012 at 01:18 UTC
Re: List Contents of Windows Directory Folder
by BrowserUk (Pope) on Dec 04, 2012 at 02:51 UTC

    What do you mean by "type"?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

      ...what he sees in the Explorer column "Type", the file type association? E.g.: Explorer shows "Firefox HTML Document" for hmtl files - if the associated action is "open with Firefox".

      Regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

Re: List Contents of Windows Directory Folder
by 2teez (Priest) on Dec 04, 2012 at 06:13 UTC

    Hi mua,
    Taking a leap from previous comments on this thread, maybe you want something like this:

    use warnings; use strict; use File::Find; use File::stat; find( \&wanted, '.' ); sub wanted { return if $_ eq '.' or $_ eq '..'; my $st = stat($_); print sprintf "Filename: %s, Size: %s, Date Modified: %s\n", $_, $ +st->size, scalar localtime $st->mtime; }
    When more files are added to this folder, I need to append to the current text file
    Please, take a look at function open
    Hope this helps

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me

      Also check out Merlyn's File::Finder, which offers a simpler interface for tasks like this.



      When's the last time you used duct tape on a duct? --Larry Wall
      This reply is also to everyone who replied for my cry for help. Thank you. 2teez, this looks like what I'm looking for. I will try it. Thanks. I will also try the other posts. Thanks.
Re: List Contents of Windows Directory Folder
by karlgoethebier (Deacon) on Dec 04, 2012 at 21:06 UTC

    With "type" you mean the suffix of the file(s), right? Here is another small solution that might do the job. Give it a try. It should be easy to order the output according to your needs. Some illuminated brothers provided already some links for further reading/diving deeper a.s.o.

    #!c:/perl/bin/perl.exe + use strict; use warnings; use IO::All; use File::Basename; my ( $in, $out, $io_objects, @line ); ( $in, $out ) = @ARGV; @io_objects = io($in)->all; for my $io_object (@io_objects) { if ( $io_object->type eq 'file' ) { @line = ( $io_object->name, ( $io_object->stat )[7], ( $io_object->stat )[9], ( fileparse( $io_object, qr/\.[^.]*/ ) )[2], ); } join( "\t", @line ) . qq(\n) >> io($out); } __END__

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1006976]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2014-04-23 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (541 votes), past polls