PDA

View Full Version : quickest way to get file/directory sizes


floopyb
05-26-2011, 05:03 AM
Is there a quicker way to get file sizes (talking tonnes of directories and Gigs of data) then just getFileSize?

lo
05-26-2011, 08:24 AM
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

Track
05-26-2011, 10:02 AM
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

floopyb
05-27-2011, 12:04 AM
This is a most fastest way to get information about file.
http://www.pinvoke.net/default.aspx/kernel32/FindFirstFile.html

Could you give me a quick example of how to use that in maxscript, im not very good outside max!

Track
05-27-2011, 07:55 PM
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: %\n" ((size as float)/(1024^2*1024)) files folders

format "Time: % sec\n" ((timestamp()-sst)/1000.0)
)

lo
05-27-2011, 07:59 PM
Looks really nice. Is this the same method used in windows explorer file properties?

denisT
05-27-2011, 08:55 PM
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

denisT
05-27-2011, 08:56 PM
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

CGTalk Moderation
05-27-2011, 08:56 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.