Active File Finder Programming Sample Codes

Document Path: Home Page / Programming / Active File Finder / Interfaces  
Clean a Folder - Remove temporary Files and Empty Folders
function CleanCallback(af, flag, file)
{
    switch(flag)
    {
    case 0:// file is a file
        var notWanted="?pch?pdb?exe?ilk?obj?idb?ncb?lib?res?dll?opt?cod?res?";
        var ext="?"+f1.ExtensionName.toLowerCase()+"?";
        var i=notWanted.indexOf(ext);
        if(i>=0)
        {
            file.Delete();
        }
        break;
    case -1: // we are at the end of a directory scanning.
        if(!file.HasChildren())
        {
            file.Delete();
        }
        break;
    }
}


function CleanDirectory(dir)
{
var af=new ActiveXObject("ActiveFileFinder.Finder");
af.ScanDirectory(dir, CleanCallback);
}

Sync Two Directories - Maximu Sync.
function SyncCallback(af, flag, f1, f2)
{
switch(flag)
{
    case 0: //f1 is file
        var notWanted="?pch?pdb?exe?ilk?obj?idb?ncb?lib?res?dll?opt?cod?res?";
        var ext="?"+f1.ExtensionName.toLowerCase()+"?";
        var i=notWanted.indexOf(ext);
        if(i<0) //not a 'not wanted'
        {
            if(!f2.Valid) //The second directoy does not have this file.
            {
                af.CopyFile(f1.Fullpath, f2.FullPath);
            }
            else
            {
                if(f1.LastWriteTime.Compare(f2.LastWriteTime)>0) //file 1 is more recent.
                {
            	    af.CopyFile(f1.Fullpath, f2.FullPath);
                }
            }
        }
        break;
    case 1: //begin scanning a directory.
        if(!f2.Valid) //The second directoy does not exits.
        {
            af.CreateDirectory(f2.FullPath);
        }
        break;
    case -1: //end scanning a directory.
        f2.LastWriteTime=f1.LastWriteTime; //Set the second directory's last-write time.
        break;
}

}

function MaxSync(dir1, dir2)
{
    var af=new ActiveXObject("ActiveFileFinder.Finder");
    af.CompareDirectroy(dir1, dir2);
    af.CompareDirectroy(dir2, dir1); //Reverse scanning.
}