denno020 Posted February 8, 2013 Share Posted February 8, 2013 Hi all, I would like to move files automatically, using a PHP script, from one folder to another. However each file will go to a different folder, so I want to only move one file at a time, and wait for the previous one to finish before I move on to the next one. I have some ideas on how I can do this, but I'm not sure how I could test it without actually implementing it and possibly locking up my system if I have too many file transfers happening at once, so I just wanted to bounce them off the knowledgeable people here. The PHP function copy will be able to do the copy for me, and it will return a true/false upon success/failure of the transfer. So I was thinking I could initiate a copy, and then have a while loop that continually loops while the function is false. When it becomes true, it will break the while loop and continue on to the next file. My only concern with this is if the file transfer does actually fail for some reason, then I wouldn't really know.. Is there any other way that would be better? I'm going to be using the script to move tv shows from one folder (where they're all mixed up), to its folder on my external hard drive (I can manage figuring out the logic for which folder a file should go to, that's not a problem). Some of the shows can be up to and over 1GB in size too, so I'm not sure if that's something that I would need to take into consideration? Hopefully I've made my problem clear and understandable. Thanks, Denno Quote Link to comment https://forums.phpfreaks.com/topic/274233-moving-files-with-php/ Share on other sites More sharing options...
trq Posted February 8, 2013 Share Posted February 8, 2013 Firstly, this sounds more like a job for something like rsync, but anyway. Secondly, your logic is completely ass about. You will end up in an infinit loop if a file fails to copy. Thirdly, why are you using copy if you want to move the files? You need to look at rename. Quote Link to comment https://forums.phpfreaks.com/topic/274233-moving-files-with-php/#findComment-1411182 Share on other sites More sharing options...
denno020 Posted February 8, 2013 Author Share Posted February 8, 2013 Must admit, responses like that make me want to leave this forum. I already said that my logic was flawed in the case of the file copy failing. Quote Link to comment https://forums.phpfreaks.com/topic/274233-moving-files-with-php/#findComment-1411188 Share on other sites More sharing options...
Technocrat Posted February 9, 2013 Share Posted February 9, 2013 You could do worker threads maybe: http://www.php.net/manual/en/book.pthreads.php Or Tasks https://github.com/jamm/Tasks Just have it spin a new one for each file and sleep until complete Quote Link to comment https://forums.phpfreaks.com/topic/274233-moving-files-with-php/#findComment-1411197 Share on other sites More sharing options...
denno020 Posted February 9, 2013 Author Share Posted February 9, 2013 You could do worker threads maybe: http://www.php.net/m...ok.pthreads.php Or Tasks https://github.com/jamm/Tasks Just have it spin a new one for each file and sleep until complete Cool thanks mate, I'll look into that. Denno Quote Link to comment https://forums.phpfreaks.com/topic/274233-moving-files-with-php/#findComment-1411198 Share on other sites More sharing options...
Technocrat Posted February 9, 2013 Share Posted February 9, 2013 If you get it working, post back, I would be interested to see what you did. Quote Link to comment https://forums.phpfreaks.com/topic/274233-moving-files-with-php/#findComment-1411200 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.