Copy function for unlimited level directory

zhaozj2021-02-16  83

Copy function for unlimited level directory

Today, I saw someone mentioned this in the forum. I wrote it for a long time. I didn't know a function like a slag. After the future research!

Function CopyDirectory ($ DIR_S, $ DIR_D) {$ DIR_S = RealPath ($ DIR_S); if (! is_dir ($ dir_s)) Return; if (! is_dir ($ dir_d)) MKDIR ($ DIR_D); if ($ DIR_S [ ! strlen ($ dir_s)] = DIRECOTRY_SEPARATOR) $ dir_s = DIRECTORY_SEPARATOR;.! if ($ dir_d [strlen ($ dir_d)] = DIRECOTRY_SEPARATOR) $ dir_d = DIRECTORY_SEPARATOR;. $ hDir_s = opendir ($ dir_s); $ hDir_d = opendir ($ DIR_D); While ($ file = readdir ($ hdir_s)) {if ($ file! = '.' && $ file! = '..') {IF (is_dir ($ dir_s. $ file) &&! is_link ($ DIR_S. $ file) {CopyDirectory ($ DIR_S. $ file, $ dir_d. $ file);} else {copy ($ dir_s. $ file, $ dir_d. $ file);}}} closedir ($ HDIR_S) CloseDir ($ HDIR_D);}

转载请注明原文地址:https://www.9cbs.com/read-13151.html

New Post(0)