www.webdeveloper.com
Results 1 to 4 of 4

Thread: check txt file

  1. #1
    Join Date
    Dec 2009
    Posts
    86

    check txt file

    hi,
    i have a text file with some text like index.php_2536
    index.php is a file name and 2536 is index.phpfile size

    my name.txt file like this
    (files/edit_profile.php_36092_files/forget_password.php_3707_files/includ.php_144_files/New Folder/New Folder/New Folder/check.php_1168_files/New Folder/New Folder/notfound.php_902_files/New Folder/New Folder/pagination_interface.php_1461_files/New Folder/notfound.php_902_files/New Folder/pagination_interface.php_1461_files/notfound.php_902_files/pagination_interface.php_1461_files/show_Rss/getrss.php_1565_)
    and i have another txt file
    name is check.txt
    he also have same method data (like name.txt)

    if in name.txt (files/edit_profile.php_36092)
    and
    if in check.txt (files/edit_profile.php_(not same above))
    (this is a one check i want full txt check in loop if any size is not same then hi give me file path (also have size like files/edit_profile.php) in a variable 1 or more only how not match )
    then hi send to email i don work in email - only want checking function

    thanx in advance............
    Last edited by aadi; 04-08-2010 at 11:04 AM.

  2. #2
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    700
    hi aadi,
    i'm not sure i understand the question.
    you have a text file that stores file sizes.
    you then have another text file that also stores file sizes, and you want to read from both and compare sizes. is that right?
    maybe a little more information on why you've structured the data that way, and what you're trying to achieve might help us help you.
    cheers
    CTB

  3. #3
    Join Date
    Mar 2010
    Posts
    672
    First off, i am assuming that your code produces two text files with the same number of records in the same order. Secondly, your text files need to have proper delimiters in order to separate the data once its ina long giant string. I took the liberty in my code with altering your delimiters:

    files/~edit_profile.php~36092>files/~forget_password.php~3707>files/somerandomdirectory/~include.php~144

    ...etc

    The complete records that includes the directory, file name, and size are separated by a > and the file size and directory is separated by a ~ in order to properly separate it without messing up file names that have the _ in them.
    PHP Code:
    $master_fs=file_get_contents(master_filesize.txt);
    $compare_fs=file_get_contents(compare_filesize.txt);

    $master_fs=explode('>',$master_fs);
    $compare_fs=explode('>',$compare_fs);

    $loopstart=0;
    while(
    $loopstart <= (count($master_fs)-1)){
    $master_fs_data=explode('~',$master_fs[$loopstart]);
    $master_fs_data_size=$master_fs_data[2];
    $master_fs_data_name=$master_fs_data[1];
    $master_fs_data_directory=$master_fs_data[0];

    // ------------------------ //

    $compare_fs_data=explode('~',$compare_fs[$loopstart]);
    $compare_fs_data_size=$compare_fs_data[2];

    if(
    $master_fs_data_size != $compare_fs_data_size){
    echo 
    'You have a file size mismatch for file '.$master_fs_data_name.' in directory '.$master_fs_data_directory.' with the original size being '.$master_fs_data_size.' and the compare size being '.$compare_fs_data_size;
    }

    $loopstart++;

    Though i'd have to say a database method would be more appropriate and less hacky than this. If you can, use a database and simply have 4 fields:
    Id
    Filename
    Directory
    Size

    You can then have your script lookup the file sizes at runtime and compare them with the ones in the database table. This would also be less error prone, because with a delimited text file, if one record is missing, all proceeding files will be reported as having a mismatch.
    Last edited by Jarrod1937; 04-08-2010 at 08:07 PM.

  4. #4
    Join Date
    Dec 2009
    Posts
    86
    Thanx Bro its working
    thanx again

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