Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. Best way to check if a file exists

Best way to check if a file exists

Scheduled Pinned Locked Moved Support
3 Posts 3 Posters 14.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S
    S
    stoffmann
    wrote on last edited by
    #1

    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.dll

    At 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

    1 Reply Last reply
    0
    • F
      F
      Filipp Sudanov
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • V
        V
        Victor Kirhenshtein
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0

        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
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        Powered by NodeBB Contributors
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups