Get size folders from file

Welcome Forums General PowerShell Q&A Get size folders from file

Viewing 4 reply threads
  • Author
    Posts
    • #257756
      Participant
      Topics: 2
      Replies: 4
      Points: 18
      Rank: Member

      Hello there,

      I want to get total folder size with PWSH (path of folder are on file),

      The content of file.txt :

      “C:\Program Files”,”C:\Program Files (x86)”

      Her the code :

      PWSH return :

      What’s wrong ? :/

       

      Thanks,

      Clement.

      • This topic was modified 3 weeks, 6 days ago by clementb27.
    • #257780
      Participant
      Topics: 16
      Replies: 1792
      Points: 3,290
      Helping Hand
      Rank: Community Hero

      Get-Content is an array of lines. If you defined an array like this in your code in-line:

      If you want to import from a file directly, normally you would separate each path on a different line:

      The goal is creating an array of paths. You can parse the line in the file with split and replace, but it.’s simpler to just format the content in the file

    • #257783
      Participant
      Topics: 8
      Replies: 606
      Points: 2,342
      Helping Hand
      Rank: Community Hero

      You say the content of the file is C:\Program Files,C:\Program Files (x86) but it is either your quotes are not valid quotes (try replacing them by typing them manually) or the are no quotes. Either of those options will lead to the error you displayed. You could also store them on on each line and use Import-Csv like this.

      You are also likely to have some items return “access is denied” errors, to keep the output neat you could use the parameter -ErrorAction SilentlyContinue on

      command. If you wanted to see what paths return error while keeping the output neat, then add

      like this

    • #257795
      Participant
      Topics: 8
      Replies: 606
      Points: 2,342
      Helping Hand
      Rank: Community Hero

      @Rob thanks for clarifying that. My testing was misleading as this works

      But this doesn’t

    • #258083
      Participant
      Topics: 2
      Replies: 4
      Points: 18
      Rank: Member

      Thanks @Rob-Simmers  -and @KrzyDoug, very helpful !

      Ticket solved, thanks a lot !

       

      Clement.

      • This reply was modified 3 weeks, 5 days ago by clementb27. Reason: bad tag
Viewing 4 reply threads
  • You must be logged in to reply to this topic.