-

把当前目录里今天改后的全部文件复制到另外目录里,有ASP版有PHP版

Visual ASP写的一个把当前目录里今天修改后的文件复制到另外目录里,PHP版在ASP版里进行了修改,使用xiyuetajs库的asp转php生成的
ASP版
<!--#include file="inc/config.asp"--><%
dim rootDirPath,toDirPath,nRootDirLen,nForDirCount
rootDirPath=handlePath("/")
toDirPath=handlePath("F:\backWeb\" & format_Time(now(),5) )
nRootDirLen=len(rootDirPath)
nForDirCount=3  '循环目录总数'

call createDirFolder(toDirPath)   '创建目标文件夹'

call echo("源目录",rootDirPath)
call echo("源目录长度",nRootDirLen)
call echo("到目录",toDirPath)
call hr()
call latestFiles(rootDirPath)
'最新文件'
function latestFiles(dirPath)
    dim content,fileEditTime,fileName,filePath,splstr,nDay,toFilePath,toFEditTime,nMiao,folderName,folderPath,newDirPath
    dim isOK,fileExt
    if right(dirPath,1)="\" then
        dirPath=mid(dirPath,1,len(dirPath)-1)
        ' call eerr("dirPath",dirPath)
    end if
    call echoYellow("文件夹",dirPath)


    '*********** 处理文件 ***********'
    content=getDirFileNameList(dirPath,"*")
    splstr=split(content,vbcrlf)
    for each fileName in splstr
        isOK=false
        filePath=dirPath & "\" & fileName
        '文件夹不为空'
        if fileName<>"" and left(fileName,1)<>"#" then
            fileExt=getFileAttr(filePath,4)
            if instr("|rar|zip|mdb|", "|"& fileExt & "|")=false then
                isOK=true
            end if
            ' call echo("fileExt文件后缀",fileExt) 
        end if
        '为真则处理文件'
        if isOK then
            fileEditTime=getFileEditDate(filePath)
            nDay=dateDiff("d", fileEditTime, now()) 
            if nDay=0 then
                call echoRed(filePath,fileEditTime  & "  - "& nDay &"天")
                newDirPath=toDirPath & "\" & mid(dirPath,nRootDirLen+1)
                call createDirFolder(newDirPath)   '创建目标文件夹'
                toFilePath=newDirPath & "\" & fileName
                '目录文件不存在' 
                if checkFile(toFilePath)=false then 
                    call echo("复制文件",toFilePath)
                    call copyFile(filePath,toFilePath) '复制文件'
                else
                    toFEditTime=getFileEditDate(toFilePath)
                    call echoBlue(toFilePath,toFEditTime  & "  - "& nDay &"天")
                    nMiao=dateDiff("s", toFEditTime,fileEditTime) 
                    if nMiao>0 then
                        call echo("相差", nMiao & "秒")
                        call echo("删除文件,并复制新文件",toFilePath)
                        call deleteFile(toFilePath)
                        call copyFile(filePath,toFilePath) '复制文件'

                    end if

                end if
            end if
        end if
    next
    call hr()
    ' call echo("文件名列表",content)

    '*********** 处理目录 ***********'
    content=getDirFolderNameList(dirPath)
    splstr=split(content,vbcrlf)
    for each folderName in splstr
        isOK=false
        folderPath = dirPath & "\" & folderName

        if folderName<>"" and left(folderName,1)<>"#" then 
            if instr("|data|404|", "|"& lcase(folderName) & "|")=false then
                isOK=true
            end if
        end if
        if isOK then
            ' call echo("folderName",folderName)        
            nForDirCount=nForDirCount-1  '每减一'
            if nForDirCount>0 then
                call echo("循环目录子文件夹 " & nForDirCount,folderPath)
                call latestFiles(folderPath)
            end if
        end if
    next
    ' call echo("文件夹列表",content)
end function
%>
    

PHP版
<?
require_once $_SERVER['DOCUMENT_ROOT'].'/Include/ASP.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/inc/time.php';

require_once $_SERVER['DOCUMENT_ROOT'].'/Include/sys_FSO.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/inc/common.php';
?>
<?PHP
$rootdirpath='';$todirpath='';$nrootdirlen='';$nfordircount='';
$rootdirpath=handlepath('/');
$todirpath=handlepath('F:\\backWeb\\php_'.format_time(now(),5));
$nrootdirlen=len($rootdirpath);
$nfordircount=3;//循环目录总数'

createdirfolder($todirpath);//创建目标文件夹'

aspEcho('源目录',$rootdirpath);
aspEcho('源目录长度',$nrootdirlen);
aspEcho('到目录',$todirpath);
hr();
latestfiles($rootdirpath);
//最新文件'
function latestfiles($dirpath){
    $latestfiles='';
    $content='';$fileedittime='';$filename='';$filepath='';$splstr='';$nday='';$tofilepath='';$tofedittime='';$nmiao='';$foldername='';$folderpath='';$newdirpath='';
    $isok='';$fileext='';
    if(right($dirpath,1)=='\\'){
        $dirpath=mid($dirpath,1,len($dirpath)-1);
        // call eerr("dirPath",dirPath)
    }
    echoyellow('文件夹',$dirpath);
    
    
    //*********** 处理文件 ***********'
    $content=getdirfilenamelist($dirpath,'*');
    $splstr=explode(vbCrlf(),$content);
    foreach($splstr as $key=>$filename){
        $isok=false;
        $filepath=trim(handlePath($dirpath.'\\'.$filename)); 
        //文件夹不为空'
        if($filename!='' && left($filename,1)!='#'){
            $fileext=getfileattr($filepath,4);
            if(instr('|rar|zip|mdb|','|'.$fileext.'|')==false){
                $isok=true;
            }
            // call echo("fileExt文件后缀",fileExt) 
        }
        aspEcho('filepath',$filepath);
        //为真则处理文件'
        if($isok){
            $fileedittime=getFileEditTime($filepath);
            $nday=datediff('d',$fileedittime,now()); 
 

            if($nday==0){
                echored($filepath,$fileedittime.'  - '.$nday.'天');
                $newdirpath=$GLOBALS['todirpath'].'\\'.mid($dirpath,$GLOBALS['nrootdirlen']+1);
                createdirfolder($newdirpath);//创建目标文件夹'
                $tofilepath=trim($newdirpath.'\\'.$filename);
                //目录文件不存在' 
                if(checkfile($tofilepath)==false){
                    aspEcho('复制文件',$tofilepath);
                    copyfile($filepath,$tofilepath);//复制文件'
                }else{
                    $tofedittime=getFileEditTime($tofilepath);
                    echoblue($tofilepath,$tofedittime.'  - '.$nday.'天');
                    $nmiao=datediff('s',$tofedittime,$fileedittime);
                    if($nmiao>0){
                        aspEcho('相差',$nmiao.'秒');
                        aspEcho('删除文件,并复制新文件',$tofilepath);
                        deletefile($tofilepath);
                        copyfile($filepath,$tofilepath);//复制文件'
                        
                    }
                    
                }
            }
        }
    }
    hr();
    // call echo("文件名列表",content)
    
    //*********** 处理目录 ***********'
    $content=getdirfoldernamelist($dirpath);
    $splstr=explode(vbCrlf(),$content);
    foreach($splstr as $key=>$foldername){
        $isok=false;
        $folderpath=$dirpath.'\\'.$foldername;
        
        if($foldername!='' && left($foldername,1)!='#'){
            if(instr('|data|404|','|'.strtolower($foldername).'|')==false){
                $isok=true;
            }
        }
        if($isok){
            // call echo("folderName",folderName)    
            $GLOBALS['nfordircount']=$GLOBALS['nfordircount']-1;//每减一'
            if($GLOBALS['nfordircount']>0){
                aspEcho('循环目录子文件夹 '.$GLOBALS['nfordircount'],$folderpath);
                latestfiles($folderpath);
            }
        }
    }
    // call echo("文件夹列表",content)
    return "";
}
?>