Hi everyone,
Does anyone have a tip on how to recursively search through directories on a FileDevice to check if a file has been saved multiple times in different folders? Maybe there’s already something out there that does this?
Thanks a lot!
Hi everyone,
Does anyone have a tip on how to recursively search through directories on a FileDevice to check if a file has been saved multiple times in different folders? Maybe there’s already something out there that does this?
Thanks a lot!
Hi Wilhelm,
I don’t know of an existing solution for this, though I wouldn’t be surprised if one exists!
My idea would be to use the FileIO library. The DirReadEx function block will give you information about files and directories inside of a file device. You could check every file it finds against your input filename and save a list of directories. You can then run your function on that list of directories and repeat the process until you’ve finished.
To my knowledge, Automation Studio doesn’t support true recursion. However, you could create a function block that is called over multiple cycles until a result is returned (though a large directory structure may take many cycles to fully check).
Hi Marcus,
thanks for the tip. I’m currently working on a solution using the FileIO library. The function block DirReadEx
gives me a data type fiDIR_READ_EX_DATA
, which includes the filename as a USINT[260]
. Do you have any advice on how I can convert that into a string?
Thanks!
A string is an array of single byte characters, so USINT[260] contains the same data as STRING[260]. You can just do a memcpy. For example, in Structured Text:
brsmemcpy(ADR(String),ADR(UsintArray),260)
Or a slightly more robust example:
brsmemcpy(ADR(String),ADR(UsintArray),MIN(SIZEOF(String),SIZEOF(UsintArray)))
I would propose to just use string copy here. String copy just copies everything it finds, until the first occurrence of a memory block of size 1 byte that is completely 0.
But in the end all of that yields the same result
brsstrcpy(ADR(String), ADR(UsintArray));