Reading a files"s name
am 05.10.2007 16:28:07 von lerameur
hi all,
I want to be able to read a file and copy that file with the same name
in another directory. I do not know the name of the file as it is a
log file, here is an example of files:
07100510555501.log
07100510555503.log
07100511555501.log
where the time stamp is 07100510 =year month day hour
and 5555 = constant
01 03, interval constant, two per hour.
I can read a file with time stamp only. but adding the constant and
interval constant is throwing me off track.
can some one help me
ken
Re: Reading a files"s name
am 05.10.2007 16:43:31 von Josef Moellers
lerameur wrote:
> hi all,
>=20
> I want to be able to read a file and copy that file with the same name
> in another directory. I do not know the name of the file as it is a
> log file, here is an example of files:
>=20
> 07100510555501.log
> 07100510555503.log
> 07100511555501.log
>=20
> where the time stamp is 07100510 =3Dyear month day hour
> and 5555 =3D constant
> 01 03, interval constant, two per hour.
>=20
> I can read a file with time stamp only. but adding the constant and
> interval constant is throwing me off track.
> can some one help me
Your question is not very clear.
What have you tried so far ("I can read a file with time stamp only.")=20
and where are your problems in that code?
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
Re: Reading a files"s name
am 05.10.2007 17:17:48 von lerameur
On Oct 5, 10:43 am, Josef Moellers
siemens.com> wrote:
> lerameur wrote:
> > hi all,
>
> > I want to be able to read a file and copy that file with the same name
> > in another directory. I do not know the name of the file as it is a
> > log file, here is an example of files:
>
> > 07100510555501.log
> > 07100510555503.log
> > 07100511555501.log
>
> > where the time stamp is 07100510 =3Dyear month day hour
> > and 5555 =3D constant
> > 01 03, interval constant, two per hour.
>
> > I can read a file with time stamp only. but adding the constant and
> > interval constant is throwing me off track.
> > can some one help me
>
> Your question is not very clear.
> What have you tried so far ("I can read a file with time stamp only.")
> and where are your problems in that code?
>
> --
> These are my personal views and not those of Fujitsu Siemens Computers!
> Josef Möllers (Pinguinpfleger bei FSC)
> If failure had no penalty success would not be a prize (T. Pratc=
hett)
> Company Details:http://www.fujitsu-siemens.com/imprint.html
I want to read these filename
07100510555501.log
07100510555503.log
07100510555505.log
07100511555501.log
07100511555503.log
07100511555505.log
07100512555501.log
07100512555503.log
07100512555505.log
etc
I want to change parameters in every log files and save them with the
same name.
Right now I use for testing filenames with one log per hour, so I can
use his:
my $filename =3D glob("$year2$month2$day2$*")
and have the hours increase by one. That is easy
Now I have three log per hour, with 3 different endings.
K
Re: Reading a files"s name
am 05.10.2007 17:41:33 von kenslaterpa
On Oct 5, 11:17 am, lerameur wrote:
> On Oct 5, 10:43 am, Josef Moellers
>
>
>
> siemens.com> wrote:
> > lerameur wrote:
> > > hi all,
>
> > > I want to be able to read a file and copy that file with the same name
> > > in another directory. I do not know the name of the file as it is a
> > > log file, here is an example of files:
>
> > > 07100510555501.log
> > > 07100510555503.log
> > > 07100511555501.log
>
> > > where the time stamp is 07100510 =3Dyear month day hour
> > > and 5555 =3D constant
> > > 01 03, interval constant, two per hour.
>
> > > I can read a file with time stamp only. but adding the constant and
> > > interval constant is throwing me off track.
> > > can some one help me
>
> > Your question is not very clear.
> > What have you tried so far ("I can read a file with time stamp only.")
> > and where are your problems in that code?
>
> > --
> > These are my personal views and not those of Fujitsu Siemens Computers!
> > Josef Möllers (Pinguinpfleger bei FSC)
> > If failure had no penalty success would not be a prize (T. Pra=
tchett)
> > Company Details:http://www.fujitsu-siemens.com/imprint.html
>
> I want to read these filename
> 07100510555501.log
> 07100510555503.log
> 07100510555505.log
> 07100511555501.log
> 07100511555503.log
> 07100511555505.log
> 07100512555501.log
> 07100512555503.log
> 07100512555505.log
> etc
> I want to change parameters in every log files and save them with the
> same name.
> Right now I use for testing filenames with one log per hour, so I can
> use his:
> my $filename =3D glob("$year2$month2$day2$*")
> and have the hours increase by one. That is easy
>
> Now I have three log per hour, with 3 different endings.
>
> K
I am not sure I understand your question totally.
If you are changing all of the log files, why not use the readdir
function to get the file names?
perldoc -f readdir
HTH, Ken
Re: Reading a files"s name
am 05.10.2007 17:49:59 von lerameur
On Oct 5, 11:41 am, kens wrote:
> On Oct 5, 11:17 am, lerameur wrote:
>
>
>
> > On Oct 5, 10:43 am, Josef Moellers
>
> > siemens.com> wrote:
> > > lerameur wrote:
> > > > hi all,
>
> > > > I want to be able to read a file and copy that file with the same n=
ame
> > > > in another directory. I do not know the name of the file as it is a
> > > > log file, here is an example of files:
>
> > > > 07100510555501.log
> > > > 07100510555503.log
> > > > 07100511555501.log
>
> > > > where the time stamp is 07100510 =3Dyear month day hour
> > > > and 5555 =3D constant
> > > > 01 03, interval constant, two per hour.
>
> > > > I can read a file with time stamp only. but adding the constant and
> > > > interval constant is throwing me off track.
> > > > can some one help me
>
> > > Your question is not very clear.
> > > What have you tried so far ("I can read a file with time stamp only.")
> > > and where are your problems in that code?
>
> > > --
> > > These are my personal views and not those of Fujitsu Siemens Computer=
s!
> > > Josef Möllers (Pinguinpfleger bei FSC)
> > > If failure had no penalty success would not be a prize (T. P=
ratchett)
> > > Company Details:http://www.fujitsu-siemens.com/imprint.html
>
> > I want to read these filename
> > 07100510555501.log
> > 07100510555503.log
> > 07100510555505.log
> > 07100511555501.log
> > 07100511555503.log
> > 07100511555505.log
> > 07100512555501.log
> > 07100512555503.log
> > 07100512555505.log
> > etc
> > I want to change parameters in every log files and save them with the
> > same name.
> > Right now I use for testing filenames with one log per hour, so I can
> > use his:
> > my $filename =3D glob("$year2$month2$day2$*")
> > and have the hours increase by one. That is easy
>
> > Now I have three log per hour, with 3 different endings.
>
> > K
>
> I am not sure I understand your question totally.
> If you are changing all of the log files, why not use the readdir
> function to get the file names?
>
> perldoc -f readdir
>
> HTH, Ken
Ok here are the name again:
07100510555501.log
07100510555503.log
07100510555505.log
07100511555501.log
07100511555503.log
07100511555505.log
07100512555501.log
07100512555503.log
07100512555505.log
I need to open 07100510555501.log
I can use
-glob($year$month$day$hour*)
-read the file
- hours++
then read the following file.... but oupss I have three files within
that hour.
How do I read the 01, 03 and 05 near the end of the file so I can
treat these seperatly?
k
Re: Reading a files"s name
am 05.10.2007 18:00:09 von lerameur
On Oct 5, 11:49 am, lerameur wrote:
> On Oct 5, 11:41 am, kens wrote:
>
>
>
> > On Oct 5, 11:17 am, lerameur wrote:
>
> > > On Oct 5, 10:43 am, Josef Moellers
>
> > > siemens.com> wrote:
> > > > lerameur wrote:
> > > > > hi all,
>
> > > > > I want to be able to read a file and copy that file with the same=
name
> > > > > in another directory. I do not know the name of the file as it is=
a
> > > > > log file, here is an example of files:
>
> > > > > 07100510555501.log
> > > > > 07100510555503.log
> > > > > 07100511555501.log
>
> > > > > where the time stamp is 07100510 =3Dyear month day hour
> > > > > and 5555 =3D constant
> > > > > 01 03, interval constant, two per hour.
>
> > > > > I can read a file with time stamp only. but adding the constant a=
nd
> > > > > interval constant is throwing me off track.
> > > > > can some one help me
>
> > > > Your question is not very clear.
> > > > What have you tried so far ("I can read a file with time stamp only=
..")
> > > > and where are your problems in that code?
>
> > > > --
> > > > These are my personal views and not those of Fujitsu Siemens Comput=
ers!
> > > > Josef Möllers (Pinguinpfleger bei FSC)
> > > > If failure had no penalty success would not be a prize (T. =
Pratchett)
> > > > Company Details:http://www.fujitsu-siemens.com/imprint.html
>
> > > I want to read these filename
> > > 07100510555501.log
> > > 07100510555503.log
> > > 07100510555505.log
> > > 07100511555501.log
> > > 07100511555503.log
> > > 07100511555505.log
> > > 07100512555501.log
> > > 07100512555503.log
> > > 07100512555505.log
> > > etc
> > > I want to change parameters in every log files and save them with the
> > > same name.
> > > Right now I use for testing filenames with one log per hour, so I can
> > > use his:
> > > my $filename =3D glob("$year2$month2$day2$*")
> > > and have the hours increase by one. That is easy
>
> > > Now I have three log per hour, with 3 different endings.
>
> > > K
>
> > I am not sure I understand your question totally.
> > If you are changing all of the log files, why not use the readdir
> > function to get the file names?
>
> > perldoc -f readdir
>
> > HTH, Ken
>
> Ok here are the name again:
> 07100510555501.log
> 07100510555503.log
> 07100510555505.log
> 07100511555501.log
> 07100511555503.log
> 07100511555505.log
> 07100512555501.log
> 07100512555503.log
> 07100512555505.log
> I need to open 07100510555501.log
> I can use
> -glob($year$month$day$hour*)
> -read the file
> - hours++
> then read the following file.... but oupss I have three files within
> that hour.
> How do I read the 01, 03 and 05 near the end of the file so I can
> treat these seperatly?
>
> k
How ccan I put the filename into an array? is ti possible?
this way I could Identify every field
k
Re: Reading a files"s name
am 05.10.2007 18:09:30 von glex_no-spam
lerameur wrote:
> On Oct 5, 11:49 am, lerameur wrote:
[...]
>> Ok here are the name again:
>> 07100510555501.log
>> 07100510555503.log
>> 07100510555505.log
>> 07100511555501.log
>> 07100511555503.log
>> 07100511555505.log
>> 07100512555501.log
>> 07100512555503.log
>> 07100512555505.log
>> I need to open 07100510555501.log
>> I can use
>> -glob($year$month$day$hour*)
>> -read the file
>> - hours++
Ahhh.. that doesn't compile. Next time, provide your
actual code!
>> then read the following file.... but oupss I have three files within
>> that hour.
>> How do I read the 01, 03 and 05 near the end of the file so I can
>> treat these seperatly?
>>
>> k
>
> How ccan I put the filename into an array? is ti possible?
> this way I could Identify every field
Using your example:
my @files = glob( "$year2$month2$day2$*" );
No idea why that ends with "$*"...
Re: Reading a files"s name
am 05.10.2007 18:26:31 von lerameur
On Oct 5, 12:09 pm, "J. Gleixner"
wrote:
> lerameur wrote:
> > On Oct 5, 11:49 am, lerameur wrote:
> [...]
> >> Ok here are the name again:
> >> 07100510555501.log
> >> 07100510555503.log
> >> 07100510555505.log
> >> 07100511555501.log
> >> 07100511555503.log
> >> 07100511555505.log
> >> 07100512555501.log
> >> 07100512555503.log
> >> 07100512555505.log
> >> I need to open 07100510555501.log
> >> I can use
> >> -glob($year$month$day$hour*)
> >> -read the file
> >> - hours++
>
> Ahhh.. that doesn't compile. Next time, provide your
> actual code!
>
> >> then read the following file.... but oupss I have three files within
> >> that hour.
> >> How do I read the 01, 03 and 05 near the end of the file so I can
> >> treat these seperatly?
>
> >> k
>
> > How ccan I put the filename into an array? is ti possible?
> > this way I could Identify every field
>
> Using your example:
>
> my @files = glob( "$year2$month2$day2$*" );
>
> No idea why that ends with "$*"...
ok typo
my @files = glob( "$year2$month2$day2*" );
I am now trying to use the substr function with no luck
k
Re: Reading a files"s name
am 05.10.2007 18:39:40 von glex_no-spam
lerameur wrote:
> On Oct 5, 12:09 pm, "J. Gleixner"
[...]
> my @files = glob( "$year2$month2$day2*" );
>
> I am now trying to use the substr function with no luck
I am now trying to give you the same advice..again.. Post
your code.
How can anyone help you if you don't show us what you're
trying to do?
In the meantime, read the documentation:
perldoc -f substr
Re: Reading a files"s name
am 05.10.2007 21:50:42 von paduille.4061.mumia.w+nospam
On 10/05/2007 10:49 AM, lerameur wrote:
>
> Ok here are the name again:
> 07100510555501.log
> 07100510555503.log
> 07100510555505.log
> 07100511555501.log
> 07100511555503.log
> 07100511555505.log
> 07100512555501.log
> 07100512555503.log
> 07100512555505.log
> I need to open 07100510555501.log
> I can use
> -glob($year$month$day$hour*)
> -read the file
> - hours++
> then read the following file.... but oupss I have three files within
> that hour.
> How do I read the 01, 03 and 05 near the end of the file so I can
> treat these seperatly?
>
> k
>
You can use a regular expression to capture the last two digits in the
filename.
Don't be offended, but I don't think you've given yourself enough time
to learn the Perl functions and operations. Your task is too simple for
someone who's been using Perl for a while. Please read these tutorials
and do the exercises in them:
http://perldoc.perl.org/perlintro.html
http://perldoc.perl.org/perlrequick.html
http://perldoc.perl.org/perlretut.html
Invest in a good Perl book for newbies, and you'll be happier.
--
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines. html
Re: Reading a files"s name
am 09.10.2007 11:11:52 von Joe Smith
lerameur wrote:
> my @files = glob( "$year2$month2$day2*" );
>
> I am now trying to use the substr function with no luck
Why? You don't need it.
my %processed;
for (;;sleep 60) {
foreach my $file (glob "$year2$month2$day2*") {
next if $processed{$file};
do { "something with the file" }'
$processed{$file} = localtime();
}
}
That will skip files that have already been seen and will process
only the new files.
-Joe
Re: Reading a files"s name
am 24.10.2007 11:08:50 von king
Hi Joe,
I have a similar kind of problem.
Here is my script.
======================================
#!c:\Perl\bin\perl.exe
use Strict;
use File::Copy;
#use File::find;
$dir = "1.cd.A1";
print "enter the name of the file to be copied:";
$file=<>;
chomp $file;
print "$file\n";
$filetobecopied = "//Builds/release/$dir/$file";
$newfile = "C:/dos";
print "$filetobecopied\n";
print "$newfile\n";
copy ($filetobecopied,$newfile) or print "file not found\n";
#find(\&wanted, @directories);
============================================================ =============================
here that $dir will change but the $file will always be same. So I can
hardcode that $file also. But I want to detect the new $dir added and
check and copy the file from the new directory added.
How can I do this.
On Oct 9, 2:11 pm, Joe Smith wrote:
> lerameur wrote:
> > my @files = glob( "$year2$month2$day2*" );
>
> > I am now trying to use the substr function with no luck
>
> Why? You don't need it.
>
> my %processed;
> for (;;sleep 60) {
> foreach my $file (glob "$year2$month2$day2*") {
> next if $processed{$file};
> do { "something with the file" }'
> $processed{$file} = localtime();
> }
>
> }
>
> That will skip files that have already been seen and will process
> only the new files.
> -Joe