Relevance substitution failed

(imported topic written by TJessee)

I have written a fixlet to do a file search and append it to a file. It works on some endpoints, and others it return the following error

Command failed (Relevance substitution failed ) appendfile {concatenation “%0d%0a” of (it as string) of (pathname of it & " (" & (size of it / 1000) as string & " KB)") of descendants whose (name of it contains “.bat”) of folder “c:”}

Here is a short list of the fixlet, with the DIR .bat the only one that fails occasionally.

appendfile ******************************
appendfile ********** DIR .BAT **********
appendfile ******************************
appendfile {concatenation “%0d%0a” of (it as string) of (pathname of it & " (" & (size of it / 1000) as string & " KB)") of descendants whose (name of it contains “.bat”) of folder “c:”}

appendfile ******************************
appendfile ********** DIR TEMP **********
appendfile ******************************
appendfile {concatenation “%0d%0a” of (it as string) of (pathname of it & " (" & (size of it / 1000) as string & " KB)") of descendants of folder “temp” of windows folder}

appendfile **********************************
appendfile ********** DIR System32 **********
appendfile **********************************
appendfile {concatenation “%0d%0a” of (it as string) of (pathname of it & " (" & (size of it / 1000) as string & " KB)") of descendants of system folder}

If this is a case where it runs into an error, how do I get it to continue and just put a blurb that says, could not find or something like that.

Thanks

Troy

(imported comment written by martinc)

Testing this out on my system, I would get this error only when I changed the “of folder “c:”” to point to a directory that did not exist. One thing I am wondering about is what the agent is using as the working directory. I am wondering if a change of the “c:” to “c:” might help.

Another way might be to first output the files you are looking for to a file and then read from that file. Something like this:

============================================================
waithidden cmd.exe /c dir /b /s c:*.bat > c:\temp\files.log

waithidden cmd.exe /c dir /b /s {windows folder}\temp >> c:\temp\files.log

waithidden cmd.exe /c dir /b /s {system folder} >> c:\temp\files.log

delete __appendfile

appendfile {(pathname of it & " (" & (size of it/1024) as string & " KB)%0d%0a") of files (it of lines of file “c:\temp\files.log”)}

delete c:\temp\appendfile.txt

copy __appendfile c:\temp\appendfile.txt

============================================================

If you want you could add some error checking to make sure there is something in the files.log file.

(imported comment written by GarrethJeremiah)

to write relevance that protects against non-existant operations there are a few options you can try.

  1. pluralize - e.g. files of folders instead of file of folder

  2. pre check - e.g. use an if then else <…>

  3. use error/alternation: e.g. size of file “xxx” of folder “c:” | 0

and probably a few others (relevance guards…still an if statement though)