Best way to check if a file exists
-
Hi,
I want to raise an alarm in case an outdated Office dll exists.
The path of the file is
C:\Program Files (x86)\Common Files\microsoft shared\OFFICE11\mso.dllAt the moment I use this File.Count DCI:
File.Count("C:\Program Files (x86)\Common Files\microsoft shared\OFFICE11","mso.dll",0,0)As long as the OFFICE11 folder exists this works fine, but if the folder doesn't exist it returns an error.
I can't count recursive from \microsoft shared\ for mso.dll as there is a OFFICE16 folder below it containing a mso.dll as well.
Regards
Stefan
-
You can make script DCI and process errors inside the script, e.g.:
s = $node->readAgentParameter("File.Size(/tmp/1/1.txt)"); if (s != NULL) return 1; else return 0;s != NULL condition can be actually simplified:
s = $node->readAgentParameter("File.Size(/tmp/1/1.txt)"); if (s) return 1; else return 0;I've used File.Size, as it is simpler and has just one parameter, but you can use File.Count as well.
P.S. Instead of script DCI you can use internal DCI with metric "Dummy" and have all the scripting in transformation script.
-
For version 4.3 we have also added new metric File.Type, which returns 0 if file does not exist, 1 if it is a directory, 2 if it is a device, and 3 if it is a regular file.
Best regards,
Victor
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login