Page 1 of 2
Folder size and number of files
Posted: Tue Apr 18, 2006 11:09 am
by pathfinder
How or could I write a task that looks at the size of a folder number of files in that folder, then e-mail the answer to me. The folder I would want to look at has many sub folders and files, about 350,000 files/folders and about 90 gb in size.Thanks,John Long
Folder size and number of files
Posted: Wed Apr 19, 2006 12:58 am
by Oleg
See example named "[DEMO] Folder Info Demo". This task calculates amount of files and total size of specified folder. If you haven't this example download it here. By the way, you can find more examples here.
The folder I would want to look at has many sub folders and files, about 350,000 files/folders and about 90 gb in size
I strongly recommend you to use BASIC script for such large folders, because it will work in a few times faster than example task. I'll publish a sample script some later.
Folder size and number of files
Posted: Wed Apr 19, 2006 2:47 am
by Oleg
See example below. This task calculates amount of files and total size in BASIC script. Of course you should download BASIC plugin for RoboTask.
;**********************
;* RoboTask Task file *
;* Do not edit! *
;**********************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1269303140
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task405"
Hide=INTEGER|0
ID=INTEGER|1290167819
Name=STRING|"Calc the folder size (with basic script)"
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
[Actions]
Action1=FOLDER
Action10=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER
[Actions\Action1]
ActionID=STRING|"A_DIALOG_BROWSEFOLDERS"
Enabled=INTEGER|-1
Name=STRING|"Browse for Folders"
Params=FOLDER
[Actions\Action1\Params]
caption=STRING|"Select Folder"
default=STRING|"None"
filter=STRING|"Text files|*.txt|All files|*.*|"
variable=STRING|"FOLDER_TO_CALC"
[Actions\Action10]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""FILECOUNT"""
Params=FOLDER
[Actions\Action10\Params]
varname=STRING|"FILECOUNT"
[Actions\Action2]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action2\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"0"
value1=STRING|"{folder_to_calc}"
value2=STRING|"none"
[Actions\Action3]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""You haven't chosen the folder"""
Params=FOLDER
[Actions\Action3\Params]
icon=STRING|"1"
msg0=STRING|"You haven't chosen the folder"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"
[Actions\Action4]
ActionID=STRING|"A_FLOW_ELSE"
Enabled=INTEGER|-1
Name=STRING|"Else"
[Actions\Action5]
ActionID=STRING|"BASIC_SCRIPT"
Enabled=INTEGER|-1
Name=STRING|"Basic Script"
Params=FOLDER
[Actions\Action5\Params]
line00000=STRING|"Public Const MAX_PATH = 260"
line00001=STRING|"Public Const FILE_ATTRIBUTE_DIRECTORY = &H10"
line00003=STRING|"Public Type FILETIME"
line00004=STRING|" dwLowDateTime As Long"
line00005=STRING|" dwHighDateTime As Long"
line00006=STRING|"End Type"
line00008=STRING|"Public Type WIN32_FIND_DATA"
line00009=STRING|" dwFileAttributes As Long"
line00010=STRING|" ftCreationTime As FILETIME"
line00011=STRING|" ftLastAccessTime As FILETIME"
line00012=STRING|" ftLastWriteTime As FILETIME"
line00013=STRING|" nFileSizeHigh As Long"
line00014=STRING|" nFileSizeLow As Long"
line00015=STRING|" dwReserved0 As Long"
line00016=STRING|" dwReserved1 As Long"
line00017=STRING|" cFileName As String * MAX_PATH"
line00018=STRING|" cAlternate As String * 14"
line00019=STRING|"End Type"
line00021=STRING|"Public Declare Function FindClose Lib ""kernel32"" Alias ""FindClose"" (ByVal hFindFile As Long) As Long"
line00022=STRING|"Public Declare Function FindFirstFile Lib ""kernel32"" Alias ""FindFirstFileA"" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long"
line00023=STRING|"Public Declare Function FindNextFile Lib ""kernel32"" Alias ""FindNextFileA"" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long"
line00025=STRING|"Dim FileCount As Long"
line00026=STRING|"Dim TotalSize As Double"
line00028=STRING|"Sub CalcFolder(ByVal AFolder As String)"
line00029=STRING|" Dim sh As Long"
line00030=STRING|" Dim FindData As WIN32_FIND_DATA"
line00031=STRING|" Dim res As Long"
line00032=STRING|" Dim FileName As String"
line00034=STRING|" sh = FindFirstFile(AFolder+""\*.*"", FindData)"
line00035=STRING|" If sh>=0 Then"
line00036=STRING|" res = 1"
line00037=STRING|" While res>0"
line00039=STRING|" FileNa me = Left(FindData.cFileName, InStr(FindData.cFileName,Chr(0))-1) 'because FindData.cFileName always containt 260 chars"
line00041=STRING|" If (FindData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = 0 Then 'file"
line00042=STRING|" FileCount = FileCount + 1"
line00043=STRING|" TotalSize = TotalSize + FindData.nFileSizeLow"
line00044=STRING|" Else 'directory"
line00045=STRING|" If FileName <> ""."" And FileName <> "".."" Then ' !!!important!!! skip ""."" and "".."" pseudofolders"
line00046=STRING|" CalcFolder(AFolder + ""\"" + FileName)"
line00047=STRING|" End If"
line00048=STRING|" End If"
line00049=STRING|" res = FindNextFile(sh,FindData)"
line00050=STRING|" Wend"
line00051=STRING|" FindClose(sh)"
line00052=STRING|" End If"
line00053=STRING|"End Sub"
line00055=STRING|"Sub Main"
line00056=STRING|" Dim s As String"
line00057=STRING|" FileCount=0"
line00058=STRING|" TotalSize=0"
line00059=STRING|" s = RoboTaskApp.ExpandText(""{Folder_To_Calc}"")"
line00060=STRING|" CalcFolder(s)"
line00061=STRING|" RoboTaskApp.SetUserVariable(""FileCount"", Str(FileCount))"
line00062=STRING|" RoboTaskApp.SetUserVariable(""TotalSize"", Str(TotalSize))"
line00063=STRING|"End Sub"
linecount=STRING|"64"
source=STRING|"0"
[Actions\Action6]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""Folder ""{Folder_To_Calc}"" contains """
Params=FOLDER
[Actions\Action6\Params]
icon=STRING|"1"
msg0=STRING|"Folder ""{Folder_To_Calc}"" contains "
msg1=STRING|"{FileCount} files"
msg2=STRING|"{TotalSize} bytes"
msgcount=STRING|"3"
playsound=STRING|"0"
showmessage=STRING|"1"
[Actions\Action7]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action8]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""FOLDER_TO_CALC"""
Params=FOLDER
[Actions\Action8\Params]
varname=STRING|"FOLDER_TO_CALC"
[Actions\Action9]
ActionID=STRING|"A_VARIABLES_REMOVE"
Enabled=INTEGER|-1
Name=STRING|"Remove variable ""TOTALSIZE"""
Params=FOLDER
[Actions\Action9\Params]
varname=STRING|"TOTALSIZE"
Folder size and number of files
Posted: Thu Apr 20, 2006 6:13 am
by pathfinder
Thanks for the help! I will give this a try and let you know how it works out.
Folder size and number of files
Posted: Thu May 04, 2006 8:02 am
by pathfinder
Ok I finally tried it and get this errorI: 5/4/2006 10:58:32 AM: ****** Starting task... ******************I: 5/4/2006 10:58:32 AM: Task started with priority: NormalI: 5/4/2006 10:58:32 AM: Executing "Browse for Folders"I: 5/4/2006 10:58:34 AM: Executing "Basic Script"E: 5/4/2006 10:58:34 AM: Invalid instruction. Line 40 Col 14 ""I: 5/4/2006 10:58:34 AM: Executing "Show "Folder "{Folder_To_Calc}" contains ""I: 5/4/2006 10:58:36 AM: Executing "Remove variable "FOLDER_TO_CALC""I: 5/4/2006 10:58:36 AM: Executing "Remove variable "TOTALSIZE""I: 5/4/2006 10:58:36 AM: Executing "Remove variable "FILECOUNT""I: 5/4/2006 10:58:36 AM: Task executed successfullyI modified the task slightly.;**********************;* RoboTask Task file *;* Do not edit! *;**********************[Root]ActionAfterRun=INTEGER|0Actions=FOLDERAutomat=INTEGER|-1CatID=INTEGER|1269303140ContinueOnError=INTEGER|0ExternalName=STRING|"Task405"Hide=INTEGER|0ID=INTEGER|1290167819Name=STRING|"Calc the folder size (with basic script)"Priority=INTEGER|3RunOnClose=INTEGER|0RunOnStartup=INTEGER|0ToLog=INTEGER|3[Actions]Action1=FOLDERAction10=FOLDERAction2=FOLDERAction3=FOLDERAction4=FOLDERAction5=FOLDERAction6=FOLDERAction7=FOLDERAction8=FOLDERAction9=FOLDER[Actions\Action1]ActionID=STRING|"A_DIALOG_BROWSEFOLDERS"Enabled=INTEGER|-1Name=STRING|"Browse for Folders"Params=FOLDER[Actions\Action1\Params]caption=STRING|"Select Folder"default=STRING|"None"filter=STRING|"Text files|*.txt|All files|*.*|"variable=STRING|"FOLDER_TO_CALC"[Actions\Action10]ActionID=STRING|"A_VARIABLES_REMOVE"Enabled=INTEGER|-1Name=STRING|"Remove variable ""FILECOUNT"""Params=FOLDER[Actions\Action10\Params]varname=STRING|"FILECOUNT"[Actions\Action2]ActionID=STRING|"A_FLOW_IF"Enabled=INTEGER|-1Name=STRING|"If Then"Params=FOLDER[Actions\Action2\Params]case=STRING|"0"operator=STRING|"0"type=STRING|"0"value1=STRING|"{folder_to_calc}"value2=STRING|"none"[Actions\Action3]ActionID=STRING|"A_DIALOG_MESSAGE"Enabled=INTEGER|-1Name=STRING|"Show ""You haven't chosen the folder"""Params=FOLDER[Actions\Action3\Params]icon=STRING|"1"msg0=STRING|"You haven't chosen the folder"msgcount=STRING|"1"playsound=STRING|"0"showmessage=STRING|"1"[Actions\Action4]ActionID=STRING|"A_FLOW_ELSE"Enabled=INTEGER|-1Name=STRING|"Else"[Actions\Action5]ActionID=STRING|"BASIC_SCRIPT"Enabled=INTEGER|-1Name=STRING|"Basic Script"Params=FOLDER[Actions\Action5\Params]line00000=STRING|"Public Const MAX_PATH = 260"line00001=STRING|"Public Const FILE_ATTRIBUTE_DIRECTORY = &H10"line00003=STRING|"Public Type FILETIME"line00004=STRING|" dwLowDateTime As Long"line00005=STRING|" dwHighDateTime As Long"line00006=STRING|"End Type"line00008=STRING|"Public Type WIN32_FIND_DATA"line00009=STRING|" dwFileAttributes As Long"line00010=STRING|" ftCreationTime As FILETIME"line00011=STRING|" ftLastAccessTime As FILETIME"line00012=STRING|" ftLastWriteTime As FILETIME"line00013=STRING|" nFileSizeHigh As Long"line00014=STRING|" nFileSizeLow As Long"line00015=STRING|" dwReserved0 As Long"line00016=STRING|" dwReserved1 As Long"line00017=STRING|" cFileName As String * MAX_PATH"line00018=STRING|" cAlternate As String * 14"line00019=STRING|"End Type"line00021=STRING|"Public Declare Function FindClose Lib ""kernel32"" Alias ""FindClose"" (ByVal hFindFile As Long) As Long"line00022=STRING|"Public Declare Function FindFirstFile Lib ""kernel32"" Alias ""FindFirstFileA"" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long"line00023=STRING|"Public Declare Function FindNextFile Lib ""kernel32"" Alias ""FindNextFileA"" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long"line00025=STRING|"Dim FileCount As Long"line00026=STRING|"Dim TotalSize As Double"line00028=STRING|"Sub CalcFolder(ByVal AFolder As String)"line00029=STRING|" Dim sh As Long"line00030=STRING|" Dim FindData As WIN32_FIND_DATA"line00031=STRING|" Dim res As Long"line00032=STRING|" Dim FileName As String"line00034=STRING|" sh = FindFirstFile(AFolder+""\*.*"", FindData)"line00035=STRING|" If sh>=0 Then"line00036=STRING|" res = 1"line00037=STRING|" While res>0"line00039=STRING|" FileNa me = Left(FindData.cFileName, InStr(FindData.cFileName,Chr(0))-1) 'because FindData.cFileName always containt 260 chars"line00041=STRING|" If (FindData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = 0 Then 'file"line00042=STRING|" FileCount = FileCount + 1"line00043=STRING|" TotalSize = TotalSize + FindData.nFileSizeLow"line00044=STRING|" Else 'directory"line00045=STRING|" If FileName <> ""."" And FileName <> "".."" Then ' !!!important!!! skip ""."" and "".."" pseudofolders" line00046=STRING|" CalcFolder(AFolder + ""\"" + FileName)"line00047=STRING|" End If"line00048=STRING|" End If"line00049=STRING|" res = FindNextFile(sh,FindData)"line00050=STRING|" Wend"line00051=STRING|" FindClose(sh)"line00052=STRING|" End If"line00053=STRING|"End Sub"line00055=STRING|"Sub Main"line00056=STRING|" Dim s As String"line00057=STRING|" FileCount=0"line00058=STRING|" TotalSize=0"line00059=STRING|" s = RoboTaskApp.ExpandText(""{Folder_To_Calc}"")"line00060=STRING|" CalcFolder(s)"line00061=STRING|" RoboTaskApp.SetUserVariable(""FileCount"", Str(FileCount))"line00062=STRING|" RoboTaskApp.SetUserVariable(""TotalSize"", Str(TotalSize))"line00063=STRING|"End Sub"linecount=STRING|"64"source=STRING|"0"[Actions\Action6]ActionID=STRING|"A_DIALOG_MESSAGE"Enabled=INTEGER|-1Name=STRING|"Show ""Folder ""{Folder_To_Calc}"" contains """Params=FOLDER[Actions\Action6\Params]icon=STRING|"1"msg0=STRING|"Folder ""{Folder_To_Calc}"" contains "msg1=STRING|"{FileCount} files"msg2=STRING|"{TotalSize} bytes"msgcount=STRING|"3"playsound=STRING|"0"showmessage=STRING|"1"[Actions\Action7]ActionID=STRING|"A_FLOW_ENDIF"Enabled=INTEGER|-1Name=STRING|"End If"[Actions\Action8]ActionID=STRING|"A_VARIABLES_REMOVE"Enabled=INTEGER|-1Name=STRING|"Remove variable ""FOLDER_TO_CALC"""Params=FOLDER[Actions\Action8\Params]varname=STRING|"FOLDER_TO_CALC"[Actions\Action9]ActionID=STRING|"A_VARIABLES_REMOVE"Enabled=INTEGER|-1Name=STRING|"Remove variable ""TOTALSIZE"""Params=FOLDER[Actions\Action9\Params]varname=STRING|"TOTALSIZE" Also is there a way to have the folder selected automaticly with out a popup? And is it possible to write the results to a file so I can e-mail it?Thanks,John
Folder size and number of files
Posted: Thu May 04, 2006 9:44 am
by Oleg
It seems the forum engine broke the script. It inserted odd space into word FileName. I put the script here
If you want to remove dialog for choosing the folder you should specify the folder name directly to variable FOLDER_TO_CALC. Use "Set variable" action instead of "Browse for Folders"
Folder size and number of files
Posted: Thu May 04, 2006 9:49 am
by Oleg
In order to write results use "Write Text file" action. But you can send the message directly without intermediate text file. Just write in message body this:
Folder "{Folder_To_Calc}" contains
{FileCount} files
{TotalSize} bytes
Folder size and number of files
Posted: Thu May 04, 2006 10:59 am
by pathfinder
It worked great. Thanks for the help!John
Folder size and number of files
Posted: Thu May 04, 2006 11:06 am
by pathfinder
Is it also possible to get it to tell me the file count and size on an ftp server? Because I download these files and would like to get an automated report.Thanks,John
Folder size and number of files
Posted: Fri May 05, 2006 7:28 am
by Oleg
I hope you don't want to count thousands of files on ftp server?
You easily can do this by using the "FTP File Loop" and "Increment Variable" actions.
Do you want an example?