디렉토리 카피하기
제로보드에서 G4로 갤러리 사진들을 카피하기 위해서 썼습니다만,
다른 용도로도 쓰일수 있습니다.
<?PHP
$fromDir = './vision/zboard/'; //소스디렉토리
$toDir = './gnuboard/'; //목적지
$chmod=0777; //8진수, 모두 허가
echo getcwd(); //현 디렉토리를 보여줍니다
echo '<br>';
//디렉토리 관련 에러처리
if (!is_writable($toDir))
echo 'target '.$toDir.' is not writable <br>';
if (!is_dir($toDir))
echo 'target '.$toDir.' is not a directory<br>';
if (!is_dir($fromDir))
echo 'source '.$fromDir.' is not a directory<br>';
$skipThese=array('.','..');
$handle=opendir($fromDir);
while (false!=($curFile=readdir($handle)))
if (!in_array($item,$skipThese))
{
// 디렉토리 끝에 /를 붙인경우 //가되므로 /로 바꿔줍니다.
$from=str_replace('//','/',$fromDir.'/'.$curFile);
$to=str_replace('//','/',$toDir.'/'.$curFile);
if (is_file($from))
{
if (@copy($from,$to))
{
@chmod($to,$chmod);
@touch($to,filemtime($from)); //카피된 화일의 날짜를 원래대로 해줍니다.
echo 'File copied from '.$from.' to '.$to.'<br>';
}
else
echo 'cannot copy file from '.$from.' to '.$to.'<br>';
}
}
closedir($handle);
?>
위에것을 호스트에 올려놓으시고 실행 시키시면 됩니다. 물론 위에 있는 디렉토리는 사용자에게
알맞게 바꾸셔야겠죠. 하위디렉토리는 처리하지 않았습니다.
다른 용도로도 쓰일수 있습니다.
<?PHP
$fromDir = './vision/zboard/'; //소스디렉토리
$toDir = './gnuboard/'; //목적지
$chmod=0777; //8진수, 모두 허가
echo getcwd(); //현 디렉토리를 보여줍니다
echo '<br>';
//디렉토리 관련 에러처리
if (!is_writable($toDir))
echo 'target '.$toDir.' is not writable <br>';
if (!is_dir($toDir))
echo 'target '.$toDir.' is not a directory<br>';
if (!is_dir($fromDir))
echo 'source '.$fromDir.' is not a directory<br>';
$skipThese=array('.','..');
$handle=opendir($fromDir);
while (false!=($curFile=readdir($handle)))
if (!in_array($item,$skipThese))
{
// 디렉토리 끝에 /를 붙인경우 //가되므로 /로 바꿔줍니다.
$from=str_replace('//','/',$fromDir.'/'.$curFile);
$to=str_replace('//','/',$toDir.'/'.$curFile);
if (is_file($from))
{
if (@copy($from,$to))
{
@chmod($to,$chmod);
@touch($to,filemtime($from)); //카피된 화일의 날짜를 원래대로 해줍니다.
echo 'File copied from '.$from.' to '.$to.'<br>';
}
else
echo 'cannot copy file from '.$from.' to '.$to.'<br>';
}
}
closedir($handle);
?>
위에것을 호스트에 올려놓으시고 실행 시키시면 됩니다. 물론 위에 있는 디렉토리는 사용자에게
알맞게 바꾸셔야겠죠. 하위디렉토리는 처리하지 않았습니다.
댓글 2개
20년 전
감사합니다.
18년 전
감사합니다. cp 명령어 같은건가요? 해당 디렉토리를 이동하는 건가요?
게시판 목록
그누4 팁자료실
그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.
나누면 즐거움이 커집니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 209 |
pearly
|
20년 전 | 5566 | |
| 208 | 20년 전 | 6008 | ||
| 207 | 20년 전 | 7270 | ||
| 206 |
Chani
|
20년 전 | 8595 | |
| 205 | 20년 전 | 5505 | ||
| 204 | 20년 전 | 4211 | ||
| 203 | 20년 전 | 5497 | ||
| 202 | 20년 전 | 4331 | ||
| 201 | 20년 전 | 5035 | ||
| 200 | 20년 전 | 5552 | ||
| 199 | 20년 전 | 4750 | ||
| 198 | 20년 전 | 8228 | ||
| 197 |
pardner
|
20년 전 | 4661 | |
| 196 | 20년 전 | 3918 | ||
| 195 | 20년 전 | 9710 | ||
| 194 | 20년 전 | 5686 | ||
| 193 | 20년 전 | 3225 | ||
| 192 |
pearly
|
20년 전 | 5789 | |
| 191 | 20년 전 | 8426 | ||
| 190 |
|
20년 전 | 7594 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기