Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

List Contents of Windows Directory Folder

by mua (Initiate)
on Dec 04, 2012 at 01:15 UTC ( [id://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

Replies are listed 'Best First'.
Re: List Contents of Windows Directory Folder
by toolic (Bishop) on Dec 04, 2012 at 01:18 UTC
Re: List Contents of Windows Directory Folder
by 2teez (Vicar) 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 BrowserUk (Patriarch) 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 karlgoethebier (Abbot) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (10)
As of 2024-04-18 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found