Reading a files's name

Discussion in 'Perl Misc' started by lerameur, Oct 5, 2007.

  1. lerameur

    lerameur Guest

    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
    lerameur, Oct 5, 2007
    #1
    1. Advertising

  2. 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 =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


    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. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html
    Josef Moellers, Oct 5, 2007
    #2
    1. Advertising

  3. lerameur

    lerameur Guest

    On Oct 5, 10:43 am, Josef Moellers <josef.moell...@fujitsu-
    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 =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

    >
    > 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. 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 = 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
    lerameur, Oct 5, 2007
    #3
  4. lerameur

    kens Guest

    On Oct 5, 11:17 am, lerameur <> wrote:
    > On Oct 5, 10:43 am, Josef Moellers <josef.moell...@fujitsu-
    >
    >
    >
    > 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 =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

    >
    > > 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. 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 = 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
    kens, Oct 5, 2007
    #4
  5. lerameur

    lerameur Guest

    On Oct 5, 11:41 am, kens <> wrote:
    > On Oct 5, 11:17 am, lerameur <> wrote:
    >
    >
    >
    > > On Oct 5, 10:43 am, Josef Moellers <josef.moell...@fujitsu-

    >
    > > 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 =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

    >
    > > > 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. 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 = 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
    lerameur, Oct 5, 2007
    #5
  6. lerameur

    lerameur Guest

    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 <josef.moell...@fujitsu-

    >
    > > > siemens.com> wrote:
    > > > > lerameur wrote:
    > > > > > hi all,

    >
    > > > > > I want to be able to read a file and copy that file with the samename
    > > > > > in another directory. I do not know the name of the file as it isa
    > > > > > 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

    >
    > > > > 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. 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 = 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
    lerameur, Oct 5, 2007
    #6
  7. lerameur

    J. Gleixner Guest

    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 "$*"...
    J. Gleixner, Oct 5, 2007
    #7
  8. lerameur

    lerameur Guest

    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
    lerameur, Oct 5, 2007
    #8
  9. lerameur

    J. Gleixner Guest

    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
    J. Gleixner, Oct 5, 2007
    #9
  10. lerameur

    Mumia W. Guest

    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
    Mumia W., Oct 5, 2007
    #10
  11. lerameur

    king Guest

    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
    king, Oct 24, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    805
    Roedy Green
    Jan 2, 2006
  2. ding feng
    Replies:
    2
    Views:
    2,786
    ding feng
    Jun 25, 2003
  3. Replies:
    0
    Views:
    771
  4. Bobby Chamness
    Replies:
    2
    Views:
    2,378
    Joe Smith
    Apr 22, 2007
  5. Jack-2
    Replies:
    3
    Views:
    254
    Jack-2
    Dec 24, 2003
Loading...

Share This Page