Skip to content

Instantly share code, notes, and snippets.

@notcod
Created January 16, 2021 02:13
Show Gist options
  • Select an option

  • Save notcod/ca84bd39ab0fb47bcd31863631c23d56 to your computer and use it in GitHub Desktop.

Select an option

Save notcod/ca84bd39ab0fb47bcd31863631c23d56 to your computer and use it in GitHub Desktop.
<?php
// Get array of all source files
$files = scandir("source");
// Identify directories
$source = "source/";
$destination = "destination/";
// Cycle through all source files
foreach ($files as $file) {
if (in_array($file, array(".",".."))) continue;
// If we copied this successfully, mark it for deletion
if (copy($source.$file, $destination.$file)) {
$delete[] = $source.$file;
}
}
// Delete all successfully-copied files
foreach ($delete as $file) {
unlink($file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment