in reply to Re: Re: ignore certain files in a folder search, and create a random .txt file
in thread ignore certain files in a folder search, and create a random .txt file

What warnings exactly? It should not give warnings as far as I can see. You need to be specific. There are really easy ways to do this stuff in perl. grep and glob are quite handy tools.....

# in simple pieces my $five_min = 5 / 60*24; # 5 minutes as part of day for M time my $dir = 'C:/devl/bin/timedir'; my @files_dirs = glob("$dir/*"); my @files = grep{ ! -d $_ } @files_dirs; my @want = grep{ ! m// and ! m// } @files; my @old = grep{ -M $_ > $five_min } @want; print "$_ is > 5 minutes old\n" for @old; # in one line: print "$_ is > 5 minutes old\n" for grep { ! -d and ! m/foo/ and ! m/bar/ and -M > 0.0035 } glob("C:/devl/bin/timedir/*");

cheers

tachyon

  • Comment on Re: Re: Re: ignore certain files in a folder search, and create a random .txt file
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Re: ignore certain files in a folder search, and create a random .txt file
by dkaplowitz (Novice) on Mar 19, 2004 at 21:38 UTC
    Sorry...I guess warning wasn't very specific. When I appended your code to my script, it would tell me that the file that was 5 minutes or older was "." or "..", so I guess that would be another couple of files I'd like to ignore. I am vaguely familiar with grep, but can't see how it would help in this scenario. I will read up on glob to see if that will help.

      You are posting different code to what you are running. You know perl is case sensitive? Anyway  next if $File =~ m/^\./ *will* skip* the . and .. dirs. It is better written (more spcific) as next if $File eq '.' or $File eq '..' but it will work. It will skip anything with a leading dot but that is rare on win32 as although you can use it it does not hide the files.

      C:\tmp>type test.pl #!/usr/bin/perl -w opendir D, '.' or die $!; while( $file = readdir(D) ) { next if $file =~ m/^\./; print "Got $file\n"; } C:\tmp>test.pl Got A Got bookmark.htm Got inherit.pl Got temp.dir Got temp.pag Got temp0.txt Got temp1.txt Got test.pl C:\tmp>

      No dot dirs present. No warnings. Now comment out the next.....

      C:\tmp>type test.pl #!/usr/bin/perl -w opendir D, '.' or die $!; while( $file = readdir(D) ) { #next if $file =~ m/^\./; print "Got $file\n"; } C:\tmp>test.pl Got . Got .. Got .foo Got A Got bookmark.htm Got inherit.pl Got temp.dir Got temp.pag Got temp0.txt Got temp1.txt Got test.pl C:\tmp>

      cheers

      tachyon

Re: Re: Re: Re: ignore certain files in a folder search, and create a random .txt file
by dkaplowitz (Novice) on Mar 19, 2004 at 21:56 UTC
    Adding your code from this post gives me good feedback on the age of the files in this directory. For instance:
    C:/devl/bin/timedir/1._Checking_File_Readiness_ is > 5 minutes old C:/devl/bin/timedir/2._Checking_File_Readiness_ is > 5 minutes old C:/devl/bin/timedir/3._Checking_File_Readiness_ is > 5 minutes old C:/devl/bin/timedir/4._Checking_File_Readiness_ is > 5 minutes old C:/devl/bin/timedir/5._Checking_File_Readiness_ is > 5 minutes old C:/devl/bin/timedir/6._Checking_File_Readiness_ is > 5 minutes old C:/devl/bin/timedir/_Watched_Folder_._Active_ is > 5 minutes old C:/devl/bin/timedir/Copy (2) of Copy of notsooldfile is > 5 minutes ol +d C:/devl/bin/timedir/Copy of Copy of notsooldfile is > 5 minutes old C:/devl/bin/timedir/Copy of notsooldfile is > 5 minutes old C:/devl/bin/timedir/notsooldfile is > 5 minutes old
    Now if I could tell the script to ignore *._Checking_File_Readiness_ and the file _Watched_Folder_._Active_, I think I'd be on easy street.

      !"£$%^)(* What code are you using! If you don't post it no one can see why it does not work. If you are using readir you have the *file name only* if using glob you have *full path* either way if you skip with REs that mathch these eithur using next if looping of ! /RE/ if grepping it will work. It should already have worked.

      m/\._Checking_File_Readiness_$/ m/_Watched_Folder_\._Active_$/

      cheers

      tachyon

        I didn't see your reply until today. I'm currently using the following, which is working:
        use strict; open OUTPUT, ">c:/temp/warning.txt"; my $mytime=(time); my ($File,$FileStat,$CallOutDir); chdir 'F:\Solimar_Work_Directories\XVTP\XVTP Cluster Feed' or die "Arg +hh!!! $!"; opendir(ROOT, ".") or die "Arghh!!! $!"; foreach $File (readdir(ROOT)) { next if $File=~/^\./; next if ($File eq "_Watched_Folder_._Active_"); next if ($File=~/\._Checking_File_Readiness_$/); next if (-d $File); if ($FileStat = (stat $File)[9]){ if ($FileStat <= ($mytime - 300)) { print "File older than 5min found. The file name is $File"; print OUTPUT "File older than 5min found. The file name is $Fi +le"; last; } } } close OUTPUT;