如何按顺序重命名从一系列已存在文件开始的文件(在 PHP 中)?
假设我有一个源文件夹,其中包含一堆文件,如下所示
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
,然后我有一个目标文件夹,其中包含完全相同的文件名。
如何将源文件夹中的文件添加到目标文件夹中,以便文件名如下所示:
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 approximation to this in PHP ?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 scandir (http://php.net/scandir) 循环遍历文件并获取第一个文件中的最后一个文件目录。解析出数字以确定第二个目录的起始路径。然后循环遍历第二个目录中的文件并重命名(http://php.net/rename)。
编辑:
根据@Toby在评论中的建议,
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,