Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Help Help
Bhargav Coca
Hello,
Here is my snippet, all i am trying to do is get the file list in the directory and also the information of last modification date and size of the file, I am using the right modules and stat in PERL, but ther is some wrong implimentation, can any one help me debug it pleasee. My snippet is attached to this post. My thing has to look exactly as it does in a ll command in Unix environment.
Find more posts tagged with
Comments
Migrateduser
At least initially, it looks as though it won't compile -- is this the case? You're missing a "}" in there. I haven't looked at it that closely yet, but that seems to be your first problem.
Dave
Current Environment(s):
(1) TS 6.1 SP2 on W2K3
(2) TS 6.1 SP2 on W2K
nipper
Your for each is missing the close bracket
Bhargav Coca
thank you for quick reply, i have included the closing bracket, it gives me the output as shown in the attachment. It doesn't look like the one i wanted. i wanted it as
<filename> <last modified date> <size> for each file there.
Please let me know how can i modify this code.
thanks
iwovGraduate
In case you didn't know, you can do a syntax check by
iwperl
-c
your_script
Bhargav Coca
i have done a -c option too, not a lot of help from it. Please let me know any other way to get this working.
Thanks
Adam Stoller
Try running:
find2perl /tmp -type f -ls
That should give you a significant leap forwards for what you're describing - at least in basic terms.
Alternatively, learn to write recursive subroutines in Perl and pass parameters around rather than hard-coding paths in your scripts.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
jbonifaci
What exactly do you think is wrong with the output? You say you want file size and last modified, yet I don't see you trying to get or ouput these anywhere? File size will be the 8th element returned from stat and last modified will be the 10th. You'll probably want to format file size, with something like this:
while ($size =~ s/(\d)(\d\d\d)($|,)/$1,$2$3/) {}
You will also want to do some formatting for modified time. You can do this a module or something custom. If you don't want to do it with a module, I have a function I use in one of my scripts that I wanted to be stand alone and not dependant on any modules that you could use, let me know and I can post it.
I'm assuming there is code that is missing, as the only module that you appear to be using is TeamSite::Config out of all the ones you are including.
Bhargav Coca
yes sir you are absolutely right, well the code i posted is my simplification for the example code in perl cookbook, its straight forward in the example, the problem there was the directory under which all the files are being displayed is my 'cwd'. But i don't want to know my files in cwd, i want it from other location and i also had problem fixing a href for the file , so if i can click on it it can open the file. I am posting the original file i have this works fine, gives me the list of all the files, but doesn't return me the modified date or size as such, you can run it and see , its safe and runs from any place. Please tell me how can i make this code portable to my location ( relative path to the directory) and how can i ge the date modified.
There is a typo i am doing
@ARGV
= ('..') instead of
@ARGV
= ('y:'). with y: doesn't work. so be careful.
Edited by lilleywhite on 02/16/05 01:40 PM (server time).
Adam Stoller
It would be nicer if the code provided usage output, but if you run your existing script as:
script.ipl -l[mucs] directory
(where 'l' is for long-listing and 'm', 'u', 'c', and 's' are columns to sort on ['mtime' by default, or 'atime', 'ctime', 'size' respectively)
you get output like 'ls -l' - but it will recurse.
the 'i' option doesn't seem to work as far as I can tell.
Also - the script was clearly written for Unix - and you're trying to run it on Windows - which won't work (getpwuid, getgrid functions don't work on Windows) -- you'll probably have to go through some contortions to make it look "right" on Windows.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com