Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

move all files in a folder to another?

Tags:

file

php

when moving one file from one location to another i use

rename('path/filename', 'newpath/filename'); 

how do you move all files in a folder to another folder? tried this one without result:

rename('path/*', 'newpath/*'); 
like image 299
ajsie Avatar asked Jan 17 '10 18:01

ajsie


People also ask

How do I move all files at once?

Select Them All It's the same as it is in any word processor: Ctrl + A. You'll see all of your files in the current window, or your desktop, selected. Just drag them where you want and you're all set.

How do I move all files from one folder to another using the command line?

To move one or more files: MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination To rename a directory: MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2 [drive:][path]filename1 Specifies the location and name of the file or files you want to move. destination Specifies the new location of the file.

How do I automatically move files from one folder to another?

You can automatically move files from one folder to another by using a script that uses Robocopy, a command-line utility which comes with Windows 10. To automated file transfer, you need to use Robocopy script, add frequency in days, source and destination folder paths.


1 Answers

A slightly verbose solution:

// 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); } 
like image 85
Sampson Avatar answered Oct 08 '22 22:10

Sampson