示例#1
0
        public static long GetWshFolderSize(string fldr)
        {
            IWshRuntimeLibrary.FileSystemObject fso = new IWshRuntimeLibrary.FileSystemObject();
            long size = (long)fso.GetFolder(fldr).Size;

            Marshal.FinalReleaseComObject(fso);
            return(size);
        }
 private static long DirectorySize(string pdbRepositoryPath)
 {
     IWshRuntimeLibrary.FileSystemObject FSO = new IWshRuntimeLibrary.FileSystemObject();
     using (new RAII(() => Marshal.FinalReleaseComObject(FSO)))
     {
         var directory = FSO.GetFolder(pdbRepositoryPath);
         using (new RAII(() => Marshal.FinalReleaseComObject(directory)))
         {
             var directorySize = (long)directory.Size;
             Console.WriteLine($"Directory size for '{pdbRepositoryPath}' = {directorySize} bytes ({directorySize / (1024.0 * 1024 * 1024)} GBs).");
             return(directorySize);
         }
     }
 }
示例#3
0
        public double GetWSHFolderSize(string Fldr)
        {
            //Reference "Windows Script Host Object Model" on the COM tab.
            IWshRuntimeLibrary.FileSystemObject FSO = new IWshRuntimeLibrary.FileSystemObject();
            double FldrSize;

            try
            {
                FldrSize = (double)FSO.GetFolder(Fldr).Size;
            }
            catch (DirectoryNotFoundException e)
            {
                return(-1);
            }
            Marshal.FinalReleaseComObject(FSO);
            return(FldrSize);
        }
示例#4
0
        public static void CheckTemporaryFiles(float maxMSize = 512f)
        {
            float  current;
            string path = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
            //Reference "Windows Script Host Object Model" on the COM tab.
            var FSO = new IWshRuntimeLibrary.FileSystemObject();

            try
            {
                float length = (float)FSO.GetFolder(path).Size;
                current = length / 1024 / 1024;
            }
            finally
            {
                Marshal.FinalReleaseComObject(FSO);
            }
            if (current >= maxMSize)
            {
                DeleteCache(CacheKind.TemporaryInternetFiles);
            }
        }