www.webdeveloper.com
Results 1 to 2 of 2

Thread: File Reading Problem

  1. #1
    Join Date
    Mar 2008
    Posts
    49

    File Reading Problem

    Hi,

    I have a folder which contains files named as:

    filename1_333.txt
    filename2_987.txt
    filename3_100.txt
    etc

    I want to read the files from this directory but problem is that I just have the filename that exists before "underscore" sign i.e. I have a file name filename1 and not filename1_333.txt ... is there anyway I can stilll read this file using some operators?

    You should assume that the name before _ sign is also unqiue in the folder

    thanks for kind reply

  2. #2
    Join Date
    Oct 2007
    Location
    Vienna, Austria
    Posts
    389
    Code:
    my $prefix = 'filename1';
    my ($filename) = glob("/path/to/files/$prefix*");
    if ($filename) {
        print "Found file: '$filename'\n";
    }
    else {
        print "No file matching '$prefix'\n";
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles