Count files only

Discuss RoboTask here
Post Reply
KeesB
Posts: 9
Joined: Sat Aug 08, 2009 7:13 pm
Location: Netherlands
Contact:

Count files only

Post by KeesB »

I need to just count files in the current directory. Is there an argument to FilesCount so it doesn't count files in sub folders?
Thanks,
 
Kees
 
Oleg
Site Admin
Posts: 3234
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Count files only

Post by Oleg »

You are correct, {FileCount()} variable counts the amount of files in specified folder and all subfolders.
In order to count files in specified folder only use the File Loop:

Set variable num to 0
File Loop //without subfolders
   Increment num
End Loop

Probably we need to add corresponding system functions. I wrote this into our ToDo list.
Rukbunker
Posts: 220
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Re: Count files only

Post by Rukbunker »

Bumping up an old topic, because I still face this "problem" today ;) Ofcourse the workaround works, but it will be great if that can be fixed into a system variable.
sarnusch
Posts: 69
Joined: Thu Apr 28, 2022 9:05 am

Re: Count files only

Post by sarnusch »

Hello,
I searched for a simple way to get the number of files without subfolders but I could not find it.
Is there a way to do this with system variable in the current version?
It would be very helpful if this were implemented.
Oleg
Site Admin
Posts: 3234
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Count files only

Post by Oleg »

Take a look at this example
You can count files in the loop

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|307868550
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1586"
Hide=INTEGER|0
ID=INTEGER|-23909006
LogOnAsUser=INTEGER|1
Name=STRING|"Count files in the folder"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RestrictRESTAPIAccess=INTEGER|0
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
StepPause=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""_num"" with value ""0"""
Params=FOLDER

[Actions\Action1\Params]
_rt_variables_produced=STRING|"_num"
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"_num"
varvalue=STRING|"0"

[Actions\Action2]
ActionID=STRING|"A_LOOP_FILE"
Enabled=INTEGER|-1
Name=STRING|"File Loop"
Params=FOLDER

[Actions\Action2\Params]
_rt_variables_produced=STRING|"_file"
createmode=STRING|"1"
date1=STRING|"20250922"
date2=STRING|"20250922"
destvar=STRING|"_file"
DuringDays=STRING|"1"
DuringHours=STRING|"1"
DuringMinutes=STRING|"1"
DuringMonths=STRING|"1"
file0=STRING|"c:\temp\*.*"
filecount=STRING|"1"
OlderDays=STRING|"1"
OlderHours=STRING|"1"
OlderMinutes=STRING|"1"
OlderMonths=STRING|"1"
savesize=STRING|"0"
searchkind=STRING|"0"
sort=STRING|"0"
sortby=STRING|"0"
sortorder=STRING|"0"
subdirs=STRING|"0"
timesize=STRING|"0"
WithoutPath=STRING|"0"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_INCREMENT"
Enabled=INTEGER|-1
Name=STRING|"Increment variable ""_num"""
Params=FOLDER

[Actions\Action3\Params]
incement=STRING|"1"
vaiable=STRING|"_num"

[Actions\Action4]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action5]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log message (neutral) ""{_num}"""
Params=FOLDER

[Actions\Action5\Params]
expression=STRING|"3"
message=STRING|"{_num}"
mode=STRING|"0"
type=STRING|"3"
This algorithm has the following advantages:
- You can specify any file masks
- You can apply a filter based on file time
Oleg Yershov
Post Reply