JorgeCarousel Posted November 18, 2022 Share Posted November 18, 2022 Hey guys, Does anybody have code to copy a whole folder tree with multiple levels? I want to do something like this: cp -fr /mnt/san1/src_folder/* /mnt/san2/dest_folder Using PHP without having to do a foreach because there are multiple levels (188 folders in total) Also, there are no files, only folders. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/ Share on other sites More sharing options...
requinix Posted November 19, 2022 Share Posted November 19, 2022 2 hours ago, JorgeCarousel said: Using PHP without having to do a foreach 2 hours ago, JorgeCarousel said: because there are multiple levels (188 folders in total) I don't see how those two are related. Are you able to write a function that can copy just the files in a directory? Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1602720 Share on other sites More sharing options...
ginerjm Posted November 19, 2022 Share Posted November 19, 2022 Is this a repeatable task or a one-time exercise? If it is the latter why not just use Windows or FileZilla? Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1602721 Share on other sites More sharing options...
JorgeCarousel Posted November 21, 2022 Author Share Posted November 21, 2022 It is going to be repetitive. Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1602832 Share on other sites More sharing options...
ginerjm Posted November 21, 2022 Share Posted November 21, 2022 You want to copy a folder tree that has no files in it at all to another place? And once you have done that then what will you do with this new copy-of-a-similar-tree that also has no files in it? Trying to get a feel for your problem and why you are in this position. Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1602836 Share on other sites More sharing options...
JorgeCarousel Posted November 22, 2022 Author Share Posted November 22, 2022 Correct, just folders, not files. Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1602882 Share on other sites More sharing options...
ginerjm Posted November 22, 2022 Share Posted November 22, 2022 You didn't finish your answer to my question Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1602885 Share on other sites More sharing options...
JorgeCarousel Posted November 28, 2022 Author Share Posted November 28, 2022 The new folders will be filled with files by people, I just want to have the tree ready fr them automatically instead of coping the tree manually. Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1603008 Share on other sites More sharing options...
ginerjm Posted November 28, 2022 Share Posted November 28, 2022 OK so you are giving people access to a specific set of folders in your domain to save uploaded files to.  1 - each user has their own sub-tree of these folders that only they will access? 2 - how do you control which of the folders each upload goes into? 3 - will others be able to see each others tree contents? Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1603012 Share on other sites More sharing options...
JorgeCarousel Posted November 28, 2022 Author Share Posted November 28, 2022 This is a tree for jobs/projects, so it's a common area, all the users in the job/project will have access (R/W) to it and depending on what they are putting into it decides which folder it will go to and yes they all will be able to see what he others have put in them, this is not for private use, but for a company-wide file server, the tree will not be public and it's not located in the website's folder. Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1603016 Share on other sites More sharing options...
ginerjm Posted November 28, 2022 Share Posted November 28, 2022 It is not located in the website's folder. Does that mean not part of your company domain? Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1603017 Share on other sites More sharing options...
JorgeCarousel Posted November 28, 2022 Author Share Posted November 28, 2022 The folders are going from a folder in the server to another folder and I recall my first post from /mnt/san1/folder to /mnt/san2/folder, therefore, not in the website's folder. Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1603018 Share on other sites More sharing options...
ginerjm Posted November 28, 2022 Share Posted November 28, 2022 And I asked - it is not part of your company's domain? Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1603019 Share on other sites More sharing options...
Solution JorgeCarousel Posted November 29, 2022 Author Solution Share Posted November 29, 2022 Got it to work using shell_exec and the command on top, so thanks for trying to help, but I got it to work. Quote Link to comment https://forums.phpfreaks.com/topic/315553-php-code-to-copy-a-folder-tree/#findComment-1603050 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.