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 8733541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:40:08+00:00 2026-06-13T09:40:08+00:00

I admit, as a newbie I’m really confused on how to code an iterative

  • 0

I admit, as a newbie I’m really confused on how to code an iterative process for the following operations.

Scenery: my file test.php checks the oldest .txt file in a specific directory and copies it into another directory called “backup”. After this, the same file is elaborated by “elab.php” (updates a MySQL database with some data contained in the file) and successively delete it, after a sleep time of 4 seconds.

Here is the code:

 $files = glob( '*.txt' );

 array_multisort(
 array_map( 'filemtime', $files ),
 SORT_NUMERIC,
 SORT_ASC,
 $files
 );

 $filename="$files[0]";

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

 include ("/home/mysite/directory/elab.php");

 sleep(4);

 unlink($filename);

As in the directory there is more than one .txt file, i’d like to perform a recursive process. It should repeat the operation for all .txt files until the directory becomes empty. How to do?
I’m confused because i don’t know if it is better to use “foreach” or “if” or “while”. Which is the best one? How to modify the file with the recursive check?

Thank you in advance for your help.

Mat

  • 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-13T09:40:09+00:00Added an answer on June 13, 2026 at 9:40 am
    $files = scandir('folder/');
    foreach($files as $file) {
      //do your work here
    }
    

    or

    $files = glob('folder/*.{txt}', GLOB_BRACE);
    foreach($files as $file) {
      //do your work here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, I admit it. I'm a CI newbie. I'm doing something really basic wrong
I admit I'm a total emacs and org-mode newbie. It worked great for me,
I'll admit, I'm an XML newbie. I'm having trouble validating some xml against a
Willing to admit I'm a complete .NET newbie, but I have extensive experience in
I'm not afraid to admit that I'm somewhat of a C++ newbie, so this
Before anything, I should admit that I am completely a newbie about Java Swing.
I'm a LINQ newbie, so the following might turn out to be very simple
I'm a newbie Rails developer who is getting the following error when trying to
Django newbie here. Following the documentation , I am trying the following to get
I'm a complete newbie to apache, so the the whole deployment process has been

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.