Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:21:47+00:00 2026-06-14T04:21:47+00:00

the php script below select and elaborate one by one all .txt files contained

  • 0

the php script below select and elaborate one by one all .txt files contained in a specific directory. First of all, a file is copied in a subdirectory named “copy”, after the script calls read.php so that the file is analyzed and elaborated. Finally the same file can be deleted from the main directory.
This is done to all files in the folder, until they end.

THE ISSUE: unfortunately the script stops when a 0 KB file (empty) is found. Probably the problem is read.php but I can’t modify this. So I’d like to delete automatically these unwanted empty files so that the process go on regularly.

Any suggestion? TNX

 <?php
 $files = glob( '*.txt' );
 array_multisort(
    array_map( 'filemtime', $files ),
    SORT_NUMERIC,
    SORT_ASC,
    $files
 );

 $filename="$files[0]";
 foreach($files as $filename) {

    copy($filename,"./copy/$filename"); 
    echo "<b> $filename </b>File copied<br>";   

    include ("read.php");

    sleep(4);

    unlink($filename);
    echo "$filename elaborated and deleted from the main folder.<br>";  
 }
 ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:21:48+00:00Added an answer on June 14, 2026 at 4:21 am

    use filesize() – http://php.net/manual/en/function.filesize.php – to determine the size of the file, and delete anything that is zero.

    $filename="$files[0]";
     foreach($files as $filename) {
        if (filesize($filename) > 0)
        {
            copy($filename,"./copy/$filename"); 
            echo "<b> $filename </b>File copied<br>";   
    
            include ("read.php");
    
            sleep(4);
    
            unlink($filename);
            echo "$filename elaborated and deleted from the main folder.<br>";  
        } else {
            unlink($filename);
            echo "$filename is empty and deleted.<br>";  
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The script below, test.php, is intended to be placed in a specific directory of
The script below resides in my theme's functions.php file. It is designed to show
In the script below, the my_theme element is a select list of a directory
I have a directory that I've built with the PHP script below and it
The code below gets the username/password and runs it thru the backend.php script. <?php
How do you put php within php? The script below is where I am
Below is my example script: <li><a <?php if ($_GET['page']=='photos' && $_GET['view']!==projects||!==forsale) { echo (href=\#\
I have a small script which im using to test PHP mail(), as below:
Any suggestions on how I can simplify the php script below?This was my previous
I have a PHP script that I wrote, and one of the pages connects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.