Link to home
Start Free TrialLog in
Avatar of onyourmark
onyourmark

asked on

perl script to list size and modified name of files in folder

Hello. I have a folder with about 3600 files in it. The files have names like
11-05-26_08-00-01_sina.csv
11-05-26_12-00-01_sina.csv
11-05-26_16-00-01_sina.csv
11-05-26_20-00-01_sina.csv
11-05-27_00-00-02_sina.csv
11-05-27_04-00-01_sina.csv

I would like to get a csv file which consists of the modified names of the files and their file sizes (either mb or kb is ok). By modified name, I just want the year, month and day so that for example
11-05-26_08-00-01_sina.csv  
would become
11-05-26
and if this file was 25.2 mb the entry for this file would be
11-05-26, 25.2
Can anyone help me with this?
THANK YOU.
Avatar of dda
dda
Flag of Russian Federation image

What is there are several files for single day, like in your example? 11-05-26 has 4 files.
Avatar of onyourmark
onyourmark

ASKER

Hi. Thanks for the reply!

Even if there are several files a day there can be a separate row for each one.

So it could look like

11-05-26, 25.2
11-05-26, 30.2
11-05-26, 20.8
11-05-26, 35.5

or something like that.

Thanks again.

SOLUTION
Avatar of farzanj
farzanj
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi. Thanks. To try this I should make it a file called something like sizes.pl and put it in the same directory as the files and then run it like
cd C:/appropriate directory
perl sizes.pl

Is this correct?

Thanks.
Yes.  Or if you want to run it from a different directory, you will have to change <*csv> part.
print /([^_]*)/,", ",(-s)/1024,"\n" for <*.csv>;
how can I have the result written to a file called sizes.csv?
Thanks
You can redirect the output by using >

script.pl > sizes.csv
Hi. Thanks again.
I think I may have specified this incorrectly.

A file like 11-05-26_08-00-01_sina.csv
would be 2011/5/26

but it is reading it as  11/5/2026.

is this hard to rearrange?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THANKS!!!