Number of files in a directory?

Forums Desktop Info Number of files in a directory?

This topic contains 4 replies, has 3 voices, and was last updated by Avatar ntech2 4 months, 3 weeks ago.

  • Author
    Posts
  • #1567 Reply
    Avatar
    Broadie
    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
    Glenn
    Glenn
    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
    Avatar
    ntech2
    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+
    • #1596 Reply
      Glenn
      Glenn
      Keymaster

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

      0
      • #1597 Reply
        Avatar
        ntech2
        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+
Reply To: Number of files in a directory?
Your information:




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