473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PERL: Trying to get the unix timestamp using File::stat.

Greetings all, great forum, this is my first post.

Recently trying to write a script that is designed to move files based on timestamps. I am fairly new to Perl, so please bare with me. I have written a short script that should iterate through all files in the current directory and output unix epoch time. The script in it's entirety is posted below:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5. use Cwd;
  6. use File::Find;
  7. use File::Path;
  8. use File::stat;
  9. use Time::Local;
  10.  
  11.         my $sourceDir = getcwd;
  12.  
  13.         opendir DIR, $sourceDir or die "cannot open dir $sourceDir: $!";
  14.         print "Source Dir: $sourceDir\n";
  15.         my @file = readdir DIR;
  16.         closedir DIR;
  17.         print "Attempting to read files.\n\n";
  18.         chdir($sourceDir);
  19.  
  20.    foreach my $file (@file)
  21.    {
  22.         print "file in loop: $file.\n";
  23.         my $unixT = (stat($file))[9];
  24.         print "Attempting to print stat: $unixT \n";
  25.    }
  26.  
BTW, thanks in advance :)
Jan 9 '08 #1
1 5497
KevinADC
4,059 Expert 2GB
What does your script do when you run it?
Jan 9 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
1
by: Tony | last post by:
Hello All, I'm having difficulty in using the glob function with stat. Here is a simple piece of code – ----------------------------------------------------------- #! /usr/bin/perl -w use...
0
by: Danny Jensen | last post by:
I need to test if certain processes on a unix box were running. I wanted to use whatsup gold to do the testing. First I needed to go to the whatsup configure>monitors & services menu to add this...
1
by: y1369 | last post by:
Is there a way to preserve the labels when converting Access dataset into Stata format using Stat/Transfer? The labels are built-in with look-up (or drop-down menu) within Access. But after...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
3
by: David Bear | last post by:
I'm trying to use os.chmod and am refered to the stat module. Is there are explanation of: * S_ISUID * S_ISGID * S_ENFMT * S_ISVTX * S_IREAD * S_IWRITE * S_IEXEC
2
by: ritesh | last post by:
Hi, I'm facing a problem in which I need to edit an already created file, and the editing needs to be done at the start of the file rather then appending to the file. OS - Linux,Solaris ...
6
by: one2001boy | last post by:
Hello, I tried to find the access time of a file using stat() function. but the following C code in windows vc.net 2003 always give the same access time. the same code works correctly in linux...
24
by: Joe Salmeri | last post by:
I just upgraded from Python 2.4.2 to Python 2.5.1 and have found some unexpected behavior that appears to be a bug in the os.stat module. My OS is Windows XP SP2 + all updates. I have several...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.