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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:42:28+00:00 2026-05-20T05:42:28+00:00

Say I have a source folder with a bunch of files in it like

  • 0

Say I have a source folder with a bunch of files in it like this

0_0.jpg
0_1.jpg
0_2.jpg
0_3.jpg
1_0.jpg
1_1.jpg
1_2.jpg
1_3.jpg
2_0.jpg
2_1.jpg
2_2.jpg
2_3.jpg

And then I have a target folder that has the exact same filenames in it.

How can I add the files from the source folder to the target folder so the filenames come out like this:

0_0.jpg
0_1.jpg
0_2.jpg
0_3.jpg
1_0.jpg
1_1.jpg
1_2.jpg
1_3.jpg
2_0.jpg
2_1.jpg
2_2.jpg
2_3.jpg
---------- files from the source folder from now
3_0.jpg
3_1.jpg
3_2.jpg
3_3.jpg
4_0.jpg
4_1.jpg
4_2.jpg
4_3.jpg
5_0.jpg
5_1.jpg
5_2.jpg
5_3.jpg

Is there a reasonable way to to this in PHP ?

  • 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-05-20T05:42:28+00:00Added an answer on May 20, 2026 at 5:42 am

    Use scandir (http://php.net/scandir) to loop through files and get the last file in the first directory. Parse out the numbers to determine the starting path for the second directory. Then loop through the files in the second directory and rename (http://php.net/rename).

    Edit:

    As suggested by @Toby in the comments,

    Split(‘_’,$var) will return an array
    of items in a string divided on _
    allowing easy access to the two
    numbers in the filename

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have an enumerable source, that looks like this: IEnumerable<string> source =
I have two source files created in unix folder say file1.dat and file2.dat. I
Say you have 100s of source files (.c or .cpp) files, and you want
Say you have the source of an application, and you're debugging the jar via
Let's say I have created a program in C/C++ and have a source code.
I have a source of strings (let us say, a text file) and many
Say I have a build machine and test machine and the source code is
Lets say have this immutable record type: public class Record { public Record(int x,
I have many source/text file, say file.cpp or file.txt . Now, I want to
I currently have a source control folder in TFS with all of my source

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.