[Closed] quickest way to get file/directory sizes
Is there a quicker way to get file sizes (talking tonnes of directories and Gigs of data) then just getFileSize?
This is a most fastest way to get information about file.
http://www.pinvoke.net/default.aspx/kernel32/FindFirstFile.html
you could write a c# assembly but I doubt it will be much faster. Traversing all directories manually is the only way to get a total directory size.
Here is such an example:
http://madskristensen.net/post/Calculate-the-total-size-of-a-directory-in-C.aspx
Could you give me a quick example of how to use that in maxscript, im not very good outside max!
(
fn CREATE_WIN32_FIND_DATA =
(
if classof (dotnet.getType "FindDataEx.Kernel32")!=dotNetObject do
(
local source=(dotNetClass "System.IO.File").ReadAllText @"YourPath\FindData_Example.cs" (dotNetClass "System.Text.Encoding").Default
local csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.ReferencedAssemblies.Add("System.Data.dll");
compilerParams.GenerateInMemory = on
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
if compilerResults.errors.count == 0 then
compilerResults.CompiledAssembly
else
for f in 0 to compilerResults.errors.count - 1 do (
print (compilerResults.errors.item[f].ErrorText)
print ( compilerResults.errors.item[f].Line as string)
)
)
)
CREATE_WIN32_FIND_DATA()
-- (dotNetObject "FindDataEx.Kernel32").RecurseDirectory <System.String>directory <System.Int32>level [out]<System.Int32&>files [out]<System.Int32&>folders
sst = timestamp()
size = (dotNetObject "FindDataEx.Kernel32").RecurseDirectory @"D:\" (-1) &files &folders
format "% GB |files: % |folders: %
" ((size as float)/(1024^2*1024)) files folders
format "Time: % sec
" ((timestamp()-sst)/1000.0)
)
Looks really nice. Is this the same method used in windows explorer file properties?
as i know explorer uses something different and it’s slow. Track’s sample has to beat explorer, but it will be interesting to have comparison: max built-in getfilesize VS system.io.fileinfo VS kernel32 findfirstfile
as i know explorer uses something different and it’s slow. Track’s sample has to beat explorer, but it will be interesting to have comparison: max built-in getfilesize VS system.io.fileinfo VS kernel32 findfirstfile