Ejemplo n.º 1
0
function loadDir($dir)
{
    global $SKIP_FOLDERS;
    $dirContent = array();
    // Dir content
    $dirContent['SIZE'] = 0;
    // Initialize structure
    $dirContent['DIRS'] = array();
    $dirContent['FILES'] = array();
    $fsobj = new COM('Scripting.FileSystemObject', null, CP_UTF8);
    // Requires extension=php_com_dotnet.dll
    try {
        // Try to write on the page
        $folderObj = $fsobj->GetFolder($dir);
    } catch (Exception $e) {
        // Some wiki error
        printLogAndDie("Error loading folder " . $dir . ": " . $e->getMessage());
    }
    foreach ($folderObj->Files as $fileObj) {
        // Check files in dir
        $dirContent['FILES'][$fileObj->Name] = $fileObj->Size;
        // Store file and it's size
        $dirContent['SIZE'] += $fileObj->Size;
        // Add file's size to total size
    }
    foreach ($folderObj->SubFolders as $subFolderObj) {
        // Check subdirectories
        if (in_array($subFolderObj->Name, $SKIP_FOLDERS)) {
            // Skip this folder
            continue;
        }
        $dirContent['DIRS'][$subFolderObj->Name] = array();
        // Init new dir structure
        $subDirContent = loadDir($dir . '/' . $subFolderObj->Name);
        // Load subdir data
        $dirContent['DIRS'][$subFolderObj->Name] = $subDirContent;
        // Store subdir data
        $dirContent['SIZE'] += $subDirContent['SIZE'];
        // Add subdir size to total size
    }
    return $dirContent;
    // Return Dir content
}
Ejemplo n.º 2
0
 protected function _refreshLocalWindows($myrole, $drivers)
 {
     $job = $this->_out->jobStart("traversing file system starting at {$this->_baseDir} using COM");
     //let create context for our closure
     /** @var $compare Compare_Interface */
     $compare = $drivers[Core_Engine::ROLE_COMPARE];
     $stat = $this->_fileStat;
     $baseDir = $this->_baseDir;
     $compare->updateFromLocalStart();
     $out = $this->_out;
     $root = true;
     $count = 0;
     $makePath = function ($path) use(&$baseDir) {
         return str_replace("\\", "/", substr($path, strlen($baseDir)));
     };
     //another closure for compare
     $c = function ($path) use(&$compare, &$stat, &$count, &$makePath) {
         /** @var $compare Compare_Interface */
         /** @var $stat Storage_Filesystem_FileStat */
         $obj = Core_FsObject::factoryFromStat($makePath($path), $stat->getStat($path));
         $compare->updateFromLocal($obj);
         $count++;
     };
     //currently regexp filter for windows is implemented in closure
     //for other platforms it should support Filter_Interface
     $options = $this->_options;
     $regExpFilter = function ($name, $isDir) use(&$options) {
         // TODO fix notification
         $filterConf = @$options['filter'][$options['filterType']];
         if ($isDir) {
             if (isset($filterConf['config']['dirnameFilter'])) {
                 if (preg_match($filterConf['config']['dirnameFilter'], $name)) {
                     return false;
                 }
             }
         } else {
             if (isset($filterConf['config']['filenameFilter'])) {
                 if (preg_match($filterConf['config']['filenameFilter'], $name)) {
                     return false;
                 }
             }
         }
         return true;
     };
     //empty closure will help
     $empty = function ($folder) use(&$regExpFilter) {
         //fix: without it folder that containes only files excluded by filter
         //will not be created, but it should be created as empty folder
         if ($folder->Files->Count > 0 && $folder->SubFolders->Count == 0) {
             foreach ($folder->Files as $file) {
                 /** @var $file SplFileObject */
                 if ($regExpFilter($file->Name, false)) {
                     return false;
                 }
             }
             return true;
         }
         if ($folder->Files->Count > 0 || $folder->SubFolders->Count > 0) {
             return false;
         }
         return true;
     };
     //this closure recursively iterates diretory, updating pathes with UTF8 support
     $magicScan = function ($dir) use(&$c, &$baseDir, &$root, &$magicScan, &$empty, &$out, &$regExpFilter) {
         //initialize windows's FileSystemObject
         /** @noinspection PhpUndefinedClassInspection, PhpUndefinedConstantInspection */
         $fso = new COM('Scripting.FileSystemObject', null, CP_UTF8);
         if ($root) {
             $curDir = $baseDir;
             $root = false;
         } else {
             $curDir = $dir;
         }
         //excluding folders
         //see Scripting.FileSystemObject on http://msdn.microsoft.com
         /** @noinspection PhpUndefinedMethodInspection */
         $folder = $fso->GetFolder($curDir);
         foreach ($folder->Files as $file) {
             //excluding files
             if (!$regExpFilter($file->Name, false)) {
                 continue;
             }
             $c($file->Path);
         }
         foreach ($folder->SubFolders as $folder) {
             if (!$regExpFilter($folder->Name, true)) {
                 continue;
             }
             if ($empty($folder)) {
                 //empty folders we update
                 $c($folder->Path . '/');
             } else {
                 //let's dig deeper :)
                 $magicScan($folder);
             }
         }
     };
     $magicScan($baseDir);
     $compare->updateFromLocalEnd();
     $this->_out->jobEnd($job, "done: updated info about {$count} files");
 }
Ejemplo n.º 3
0
<?php

header("Content-Type: text/plain");
$objFSO = new COM("Scripting.FileSystemObject");
$objFolder = $objFSO->GetFolder("C:\\\\Documents and Settings\\");
echo "Date created: " . $objFolder->DateCreated . "\r\n";
echo "Date last accessed: " . $objFolder->DateLastAccessed . "\r\n";
echo "Date last modified: " . $objFolder->DateLastModified . "\r\n";
echo "Drive: " . $objFolder->Drive . "\r\n";
echo "Is root folder: " . $objFolder->IsRootFolder . "\r\n";
echo "Name: " . $objFolder->Name . "\r\n";
echo "Parent folder: " . $objFolder->ParentFolder . "\r\n";
echo "Path: " . $objFolder->Path . "\r\n";
echo "Short name: " . $objFolder->ShortName . "\r\n";
echo "Short path: " . $objFolder->ShortPath . "\r\n";
echo "Size: " . $objFolder->Size . "\r\n";
echo "Type: " . $objFolder->Type . "\r\n";
echo "=======================";
Ejemplo n.º 4
0
 public function defineMd5($path)
 {
     //hack for windows encoding issue
     if ($this->_opsys == self::OPSYS_WIN) {
         $path = mb_convert_encoding($path, $this->_windowsEncoding, "auto");
         /** @noinspection PhpUndefinedClassInspection */
         $fsobj = new COM("Scripting.FileSystemObject");
         try {
             /** @noinspection PhpUndefinedMethodInspection */
             $fsobj->GetFolder($path);
             $f = true;
         } catch (Exception $e) {
             $f = false;
         }
         if ($f) {
             return md5("");
         }
         //exit("converted ".$path);
     }
     return md5_file($path);
 }