Number of files in a directory?

Forums Desktop Info Number of files in a directory?

Viewing 2 reply threads
  • Author
    Posts
    • #1567 Reply
      AvatarBroadie
      Participant

      First time poster, long time stalker, great program, really like it!

      My question is if there’s a way to monitor the number of files on a network share, either mapped or UNC?

      Thank you!

      0
    • #1568 Reply
      GlennGlenn
      Keymaster

      Number of files? Not as such. The FILE item will monitor a directory for any changes.

      A DIRECTORY item sounds feasible. It might return several values such as the current number of files, current number of sub-directories, date/time of last change, anything else we can dream up. Perhaps a wild card option to return the number of files that match.

      0
    • #1595 Reply
      Avatarntech2
      Participant

      You can write a powershell script to get the number and then run it on a schedule using task scheduler.

      Script could be something like this:

      $directory = "\\mynetwork\share"
      $output = "C:\temp\output.txt"
      (Get-ChildItem -path $directory -Recurse).count > $output

      Save that as .ps1 file. In task scheduler set it to run powershell.exe with the parameter -file “script.Ps1” and with the schedule you want.
      Now in your DesktopInfo ini file use any of the methods to read a txt file.

      1+
      Glenn
      • #1596 Reply
        GlennGlenn
        Keymaster

        Nice. how would you change that so it outputs a key=value type text file?

        0
        • #1597 Reply
          Avatarntech2
          Participant

          Depends on what we need to set as key. If we just want the output to look like this:
          Count=123123
          Then something like this will do the trick:

          $directory = "C:\temp"
          $output = "C:\temp\output.txt"
          $ItemCount = (Get-ChildItem -path $directory -Recurse).count
          "Count=$ItemCount" > $output

          By the way I realized the snippet I posted before also counts folders. If you want to only count files, then this will work:

          $directory = "C:\temp"
          $output = "C:\temp\output.txt"
          $ItemCount = (Get-ChildItem -path $directory -Recurse | where{$_.PSIsContainer -eq $False}).count
          "Count=$ItemCount" > $output
          1+
          Glenn
Viewing 2 reply threads
Reply To: Number of files in a directory?
Your information:




Cancel
Do NOT follow this link or you will be banned from the site!