PHP script for moving folders

I would like to move folders around server-sided (based on some parameters from a SQL database).
What would be the easiest practice to do so? I have a user with all rights to the datafolder. The script will run local on the same machine. For simplification, I am following the following steps:

  • List directories
  • Determine desired target location (based on MySQL db).
  • Move the folder

The first 2 steps are easily done. But for the last step I am struggling. I can move it local and rescan, but that’s not ideal. I hope anyone can point me in the right direction.


Could you please explain more regarding the third step ?
What would be the ideal ?


I would use a command-line WebDAV client like cadaver for this purpose. This way, the folders new location will be known immediately, without a rescan. You could run cadaver with a script created by the first two steps.


If you want to do this programatically have a look on these snippets:

If you are using some programming language use their WebDAV library to get your commands run.


Thanks everyone for pointing me in the right direction. I will be testing it and will report here for future reference.

Rescanning takes forever on my server and I think it’s a hacky way of doing things.

It would be ideal if I could move folders programmatically on demand in a clean way via a PHP script without accessing the filesystem directly for safety reasons. This can be 1 folder in a day, but also many folders in a minute. I think it is better/safer that ownCloud will handle the movings. Please correct me if I’m wrong!

I have used curl in my php script and it works great. Thanks a lot!