Reputation: 19
I have a folder that contain some images pic1.jpg, pic2.jpg, pic3.jpg, frame2.jpg. round.jpg
. My question is how to move only pic*.jpg
images to a new folder without adding the other images frame*.jpg
and round.jpg
using php
Upvotes: 0
Views: 45
Reputation:
// search for all the pathnames matching pattern
foreach(glob("/myfolder/pic*.jpg") as $file)
{
// check if newfolder exists, if not create it
if(!is_dir('/newfolder') && !file_exists('/newfolder')) {
mkdir('/newfolder', 0755);
}
// new file path
$newfile = '/newfolder/'.basename($file);
// copy file to new location
copy($file, $newfile);
}
Upvotes: 0
Reputation: 98901
foreach(glob("/old/pic*.jpg") as $file)
{
rename($file, "/new/".basename($file));
}
Upvotes: 1