Programming :: Perl Script To Count Files And Directories Is Not Working?

Aug 26, 2010

I am new to perl scripting and wrote a perl script to read the directories and files and count the no of files in each directory and generate a log file. The problem is it is not printing anything to the log file. I am copying the script below.

!/usr/local/bin/perl
$dir= 'c:My ProjectsPerl ScriptsNew Folder' ;
$directory_count = 0;
$file_count=0;

[code].....

View 14 Replies


ADVERTISEMENT

Programming :: PERL Count Files In A Dir?

Jul 8, 2009

I need to count files in a dir which were updated yesterday.

ls -lth | grep -i 'Jul 7' | wc -l

The dir holds files of last 15 days and total count is as 2067476. Is it efficient to count the files using perl? I have developed the following perl script making use of system().

Code:

#!/usr/bin/perl
@months = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
($sec,$min,$hour,$monthday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

[code]....

View 12 Replies View Related

Programming :: Count Occurrency Of Each Array Element - Perl?

May 10, 2010

Exist it a perl function to count how much each array element is into array?

View 14 Replies View Related

Programming :: Can Perl Move X Amount Of Directories

Jan 8, 2010

I'm in the midst of making a perl script and I was wondering if it was possible, to say, have a folder with 20 files in it, then move 5 files out of there, into a new one. I would like to to do this until the original folder has no more files in it, but I'm very stuck.

View 3 Replies View Related

Programming :: Count The Files For Each Sub Folder?

Jan 11, 2011

I want to count the number of files in each sub folder of a directory structure. At the moment I can do:

ls -1R /Folder | wc -l

Which lists the item count for all the folders as one. I can do:

ls -1R /Folder wc l

Which lists all the folders in the top level and all the items. Is there any way to get the list of folders and then item count for each folder?

View 1 Replies View Related

Programming :: Find Files Older Than X And Count Them?

Nov 29, 2010

I have log files that should be parsed and then deleted by a script on a regular basis. Sometimes things don't work for a variety of reasons and the log files sit and sit and are never dealt with. What I need is a small script that can give me the files older than X days and a count of those files.

What I have so far helps me take care of things manually but I need a little automation in my life Here is what I have: I can count all the files in the necessary directories recursively with this: ls -laR | wc -l And I can find all the files that are older than 10 days that haven't been deleted yet by doing this: find /home/mike/logs -type f -mtime +10 But how do I put both of them into a script that will just give me the end number of both?

View 5 Replies View Related

Programming ::Word Count For All Files In A Directory?

Apr 7, 2011

Word Count for all files in a directory

View 1 Replies View Related

Programming :: DBD::mysql::st Execute Failed: Column Count Doesn't Match Value Count At Row 1

Feb 24, 2010

I have the following perl/DBI script:

Quote:

#!/usr/bin/perl
use DBI;
my ($db, $user, $pw) = ('dbname', '****', '***********');
my $dbh = DBI->connect("DBI:mysql:$db",$user,$pw) or die "Cannot connect to $db: $DBI::errstr

[code].....

The error message is

[Wed Feb 24 13:03:27 2010] myscript.cgi: DBD::mysql::st execute failed: Column count doesn't match value count at row 1 at myscript.cgi. [Wed Feb 24 13:03:27 2010] myscript.cgi: DBI::db=HASH(0x8a30c60)->errstr

View 2 Replies View Related

Programming :: Bash Script To Find Newest Files And Count Them?

Feb 25, 2010

I'm working on a bash script that will go through a directory, find the sub-directories that have been created since the last time the script ran, count the results, and output that integer (will most likely be '1' or less per each instance run) to a file. Give the circumstances, my previous (and very limited) experience with bash is not sufficient for me to pull this off. since it probably has bearing, is that my mail server stores files that it flags as viruses in a folder. It creates a sub-directory for each virus that it quarantines .I want to count those subdirectories and graph them with MRTG. Hence the script. I'm going to post what I've got so far and the purpose of it, because I'm told I have a very odd and efficient way of doing scripting.

[Code]...

But then it dawned on me that it wouldn't work because I would have to not count the directories that have already been counted and count the ones that have not been counted. Given that the purpose of this is to generate a graph about every 5 minutes, using find won't work because, to my knowledge, that will only find things based on whole day values, I need it almost down to the minute.

View 1 Replies View Related

Programming :: Perl - Directories Given To Opendir Via Foreach Give "No Such File Or Directory" Error

Feb 19, 2009

I'm writing a perl script to remove a test database and part of that is of course getting rid of all files. So I wrote this to do the job:

Code:

This always results in an "Could not open /u00/app/oracle/product/10.2.0/rdbms/dbs for reading: No such file or directory" (that directory is the one ending with the $spfile_dir variable) message, although that directory exists and the executing user has writing rights on it.

The same behaviour if I create the directory array like this:

Code:

The problem does not occur when one of the directories is the only element in the array though. Of course I could copy and paste that part of the script for the second directory, but I don't like that workaround.

View 1 Replies View Related

Programming :: Sort Files In Directories Based On Files Date

Sep 8, 2009

I need a script that will take all the files in a given directory and create new monthly sub-directories and sort all the files based on the creation date into the appropriate directory.For example, all files created between 01/01/09 and 01/31/09 will be placed in 'JAN-2009'

View 5 Replies View Related

Programming :: How To Get Perl Qt4 Working

Jul 24, 2010

I really would like Perl Qt4 bindings. The best I could find is this:[URL]The problem is that the sources would not compile, and the RPMs are for 32-bit machines.Is there really no such thing as good Perl Qt4 bindings?

View 8 Replies View Related

Programming :: Comparing Two Files In Perl ?

Oct 9, 2009

I would like to ask opinion from perl experts.

I want to compare 2 files and show the differences in a text file.

For example, if i open File A an B in notepad

File A:

File B:

Quote:

line3 is missing in File B

So if I did a File compare (line by line), the differences will be in line3, line4, line5, line 6.

But I dont want it to be like that.

I want it to be like this

Quote:

Can Text:: Diff able to perform the work.

View 1 Replies View Related

Programming :: Download Files Using Perl?

Jul 24, 2010

How do I download a file to a specified location on disk in Perl?I tried doing a few web searches but suprisingly couldn't find anything.

View 4 Replies View Related

Programming :: Processing Files Using Perl?

Aug 23, 2010

I am looking for some suggestions if possible, regarding processing the files using perl script. Scenario is I have a location where new files will be added always. I need to process these files for some validation. I wrote a perl script to do this and I thought I can rename the files once they are processed in that way I dont process the same files again. But now I can't rename the files due to some restrictions. Second thought, to process them based on date stamp but as my perlscript is being automated and runs every one hour to process the files I can't go by date stamp.

View 5 Replies View Related

Programming :: Determine Files And Directories?

Mar 9, 2010

i made a program to list all the files in a directory,is there a way to determine what are directories and what are files ?

View 5 Replies View Related

Programming :: Simple Perl Log Code Not Working?

May 25, 2010

I just upgraded servers, and I'm now on 'perl v5.8.8 built for i386-linux-thread-multi' and a simple log script doesn't work. I got it changed to

Code:
#!/usr/bin/perl
use strict;

[code]....

View 4 Replies View Related

Programming :: Copy Files To Dynamic Directories?

Feb 14, 2011

I have been searching for a solution to the following problem:

When my distro of choice updates Firefox web browser, the directory name is '/usr/lib/firefox-<version>'.
The problem here is that the directory name is dynamic by nature and doesn't allow a simple static solution, e.g.
'cp -rf /usr/local/files/bookmarks.html /usr/lib/firefox/defaults/profile'.

The same quandary applies when adding extensions, changing prefs etc.
I have looked at the following commands:-
find, sed, xargs, grep, awk, fprint.
Unfortunately my grasp of syntax and programming is very simple at best.

View 2 Replies View Related

Programming :: Compare Two Files Using Perl Or Shell Scripting?

Mar 8, 2010

I want to compare the following two tab-delimited .txt files (both were subsets of the original files) by comparing Columns 3 and 4 simultaneously. It is easy to compare C3 because both C3s are just numbers. But how to compare C4s?Basically, in File1, "G,G" = G in File2, "C,C" = C in File2, "A,A" = A in File2, "T,T"= T in File2.In File2, A/T in Column4 just equals "A,T" or "T,A" in Column4 of File1. C/T in Column4 just equals "C,T" or "T,C" in Column4 of File1, and etc.

File1:

C1C2 C3C4
ih509rs12345467244750"G,G"
ih499rs6049687244911"C,C"
ih508- 7244977"A,A"

[code]....

View 2 Replies View Related

Programming :: Perl - Counting Files With File - Find

Dec 20, 2010

So this is my code:

Code:

Modification of code I found here. It works, but I don't really know why.

Q1: Why is each filter hit counted only when the conditional is not true?

Q2: I've tried taking the file type, (.old), and put it into a variable for better usability, but then the script fails.

View 14 Replies View Related

Programming :: Cmake - Using Header Files In Higher Directories ?

Nov 1, 2010

Say I have a directory structure:

And other.c has:

How do I setup the CMakeFiles.txt files in each directory, so the executable "program" (from program.c) is created.

Currently I get the error:

View 1 Replies View Related

Programming :: Make List Of Directories Which Contain Files Other Than Subdirs?

Oct 17, 2009

I need to, through a bash script, go through a given directory (given as argument 1) to list out the relative path in this directory (including $1) for eact subdirectory which contains files. Directories which only contain . .. and eventually only subdirectories SHALL NOT be listed. It is this last requirement that makes it difficult for me.

I have been using the tree command for now, but I have not found a way to ignore paths to directories which only contains other subdirs or nothing at all in any easy way. I may offcourse test each directory after they are listed but this gives an extra loop to go through and I beleive it should be possible to do it directly when creatring the list. I guess by using find or ls in conjuntion with the tree command or by itself it should be possible but I am not to conversant of nested script commands.

View 9 Replies View Related

Programming :: Change Current Working Directory Through A Perl Script?

May 2, 2010

how can i actually switch to another directory with "chdir" in perl.like the we used to do is bash as:

Code:
$cat abc
cd Desktop/

[code]...

View 1 Replies View Related

Programming :: Standardize A Perl Script So That Can Use It No Matter How Many Input Files

Mar 21, 2010

I need write a script that can compare multiple input files and output a file. The basic idea is:1: All my input files are in the same format2: I want to find in-common lines (in-common 1) from some of my input files (e.g., input1, 2 an 3), and find in-common lines (in-common 2) from the rest of my input files (e.g., input 4,5,6,7). And then, compare in-common1 and in-common2 and remove any overlap from in-common 1.3: Output the remaining in-common 1 file after removing any of its overlap with in-common 2I know how to write this script by putting all the filenames in one script and compare them. But the thing is, if I have more input files, such as 100, it might not be that efficient to write all filenames in one script and compare them.

I am wondering if there is any way to do such as:1: put all input filenames in a text file (file1)2: write a script3: Everytime, when I run this script, it will read in file1 directly no matter how many input files I have, give an output.I want this because I will have more and more input files and I don't wanna add multiple lines in the script just for reading the new inputfiles and compare them with the previous files. So, I guess this is something related to making my script a package or standardize it and make it easy to use in the future no matter how many input files I will have.

View 5 Replies View Related

Programming :: Moving Files To Directories Based On Part Of Filename?

Jul 6, 2010

I have a single directory of pairs of files, with the pairs sharing a string as the beginning of the filename:

SF1-27F1492R-clone01_T3_A18_001.ab1
SF1-27F1492R-clone01_T7_A20_002.ab1
SF1-27F1492R-clone02_T3_A19_003.ab1
SF1-27F1492R-clone02_T7_A21_004.ab1
...etc

I need to create a subdirectory for each pair then move the pair into the subdirectory.

I accomplished the first step using:

$find /foo -name '*T3*' -exec mkdir '{}.wrk' ;

I can use a regex to designate the pair and associate the directory, but how do I use regex in a path as the output of a move command?

View 7 Replies View Related

Programming :: Java Preferences - Web Suggested Things Like Hidden Files Or Directories

Mar 28, 2011

I am trying to understnd where java preferences are stored based on web search I understand they are somewhat like windows registry - stored out there somewhere. web suggested things like hidden files or directories - and i've look all over th eplace withour result on Fedora 14. trying to start a program. got part way in and had given some info and then it blew. it still remembers my iput - which may have been wrong. ive looked at code and see it uses the java preferences system - wpould like to find and erase.

View 2 Replies View Related

Programming :: Shell Script To Rename All Patern Mateched Directories And Files?

Jul 11, 2011

I have one directory with 3 level sub-directories, and about houndard files under those directories. I need a shell script to rename all patern mateched directories and files.

For example: the patern is AA in the directory or file name.

View 14 Replies View Related

General :: Create A Backup Directory And 3 Directories Within That And Some Files Within The 3 Directories And Then Back Them Up Ot Restore Them?

Dec 19, 2009

i am in need of linux help. iam at college and i need this back/restore script to pass this final part of an assessment. i require a backup script that will not only backup but also restore files to the relevent directories. e.g. users are instructed to store all wordprocessor files in a directory named wp. so i am needing to create a backup directory and 3 directories within that and some files within the 3 directories and then back them up ot restore them. l know i should/have to do this myself by been trying to get/understand info for the last few days and came up with zero.

View 14 Replies View Related

General :: How To Store Files / Directories In Different Different Directories?

Mar 23, 2011

I am writing a script, in that my requirement is, if all the fill types stored in one directory from that we need to separate different different directories based on the file types.

for example in a directory(anish). 5 different types files
1- directory
2- .txt files
2- .sh files

like that and my requirement is the (1- directory is moved to one new directory(dir) which we are given in the script)and (2 .txt files are moved to another new directory(test) which we are given in the script)and ( 2 .sh files are moved to another new directory(bash) which we are given in the scrip)finally the directory anish should be empty..using bash script.how it is possible !!

View 7 Replies View Related

General :: Count Files In Dir Then Move That Many Files In A Script?

Dec 17, 2009

what I got - from a crontab run a script (understand that part), this script needs to count the amount of files in /outgoing/, then take 30 less that number, and move that many files from /readycalls/. I need to keep the asterisk outgoing que full of .call files with out having to many in there at any given time.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved