Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move one directory to another directory?

Tags:

file

php

I have two folders

  1. myappdemo.com/VueGuides/services/iclean

  2. myappdemo.com/VueGuides/services/pics

I need to move iclean folder into pics folder using PHP.

like image 628
Ajay Avatar asked Dec 09 '11 13:12

Ajay


People also ask

How do I move a directory to another directory in Unix?

The mv (move) command is used to move one or more files or directories from one directory to another directory using terminal in the Linux/Unix operating system. After using the mv command file is copied from source to destination and source file is removed. The mv command is also used to rename the file.

Can you move one directory to another directory Linux?

To move a file or directory from one location to another, use the command mv. Common useful options for mv include: -i (interactive) — Prompts you if the file you have selected overwrites an existing file in the destination directory. -f (force) — Overrides the interactive mode and moves without prompting.


1 Answers

Use rename(). Note that if this runs on a web server, the web server user must have access to write to the target directory.

rename("oldpath", "newpath");

// in your case, assuming the script calling rename() 
// resides in the directory above 'myappdemo.com'
rename("myappdemo.com/VueGuides/services/iclean", "myappdemo.com/VueGuides/services/pics/iclean");

// Or use full absolute paths
rename("/path/myappdemo.com/VueGuides/services/iclean", "/path/myappdemo.com/VueGuides/services/pics/iclean");
like image 99
Michael Berkowski Avatar answered Oct 19 '22 05:10

Michael Berkowski