Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9256597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:58:55+00:00 2026-06-18T11:58:55+00:00

I want to develope a script that will log the size of the folders

  • 0

I want to develope a script that will log the size of the folders in a given directory, their name’s, and the date when they were logged. I want the script to export in the following CSV format:

Date;A;b;c;durga;New Folder;New Folder (2)
0125-1416;0.00;0.05;1;1; 0.00
0125-1417;0.00;0.05;0.00;0.00
0125-1419;0.00;0.05;0.00;0.00;20;30

Finally, i want the script to be intelligent enough to determine, based off of this log file, that there have been folders either added or removed. So if my root directory, C:\scripts has folders A, B, and C. I want the script to know if i delete A or add D the next time it runs and account for that in my CSV file.

The script is to be ran every so often (daily?) and basically append a new row to the ever increasing in size CSV file called ‘log.txt’.

So far, I have some code that recurses through my folders and sums up their individual sizes, saves the name of the parent folder, it’s size, and date and wedges all this information into a new object which is then tossed into an array index. I’m lost when trying to get a bunch of similarrly formatted objects to look like my desired CSV output. There’s got to be a better approach for getting a CSV file out of this!!

Here’s my ‘get size of folders in a given directory’ bit of code:

cd C:\scripts
$a = @()
get-childitem | where {$_.PSIsContainer} | foreach   {
$size = (Get-ChildItem $_ -recurse | where {!$_.PSIsContainer} | Measure-Object -Sum Length).Sum
$date = Get-Date -UFormat %Y%m%d-%H%M
$size1 = "{0:n2}" -f ($size / 1MB) 
$obj = new-object psobject
add-member -inp $obj noteproperty date $date
add-member -inp $obj noteproperty path $_.Name
add-member -inp $obj noteproperty size $size1 
$a += $obj 
}

I’m new to Powershell so this is where i’m getting tripped up: I have the sizes of my folders, I don’t know how to extract my objects in $a, format them all pretty (like the example CSV i posted up towards the beginning of my post), get em saved as a CSV, have the script be intelligent enough to read the CSV the next time the script is ran and account for changes when it records the next line of the CSV file.

Is there a better way to do this? This is my first post after a year of super-lurking so please be gentel… lol.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:58:56+00:00Added an answer on June 18, 2026 at 11:58 am

    I gave it a try. I replaced your get-date format to match the output, because they didn’t match in your sample. This creates one column for each folder. Columns are never deleted, just added. So if a new folder is added, a new column will appear in all records with values only in the records where it existed. If a folder is deleted, previous records will have a null value in that column.

    cd C:\scripts
    $filename = "log.csv"
    $out = @()
    
    $date = Get-Date -Format MMdd-HHmm
    
    #Create new record
    $rec = New-Object psobject -Property @{
        Date = $date
    }
    
    Get-ChildItem | where {$_.PSIsContainer} | foreach {
        $size = (Get-ChildItem $_.FullName -recurse | where {!$_.PSIsContainer} | Measure-Object -Sum Length).Sum
        $rec | Add-Member -MemberType NoteProperty -Name $_.Name -Value ("{0:n2}" -f ($size / 1MB))
    }
    
    
    #Check if file exists and get columns
    if (Test-Path $filename -PathType Leaf) {
        $in = Import-Csv $filename
        $incol = $in | Get-Member -MemberType NoteProperty | % { $_.Name }
        $reccol = $rec | Get-Member -MemberType NoteProperty | % { $_.Name }
    
        #Add missing columns to exisiting records
        Compare $incol $reccol | ? { $_.SideIndicator -eq "=>" } | % { $in | Add-Member -MemberType NoteProperty -Name $_.InputObject -Value $null }
        #Add missing columns to new record
        Compare $reccol $incol | ? { $_.SideIndicator -eq "=>" } | % { $rec | Add-Member -MemberType NoteProperty -Name $_.InputObject -Value $null }
    
        $out += $in
    }
    
    $out += $rec
    
    $out | Export-Csv $filename -NoTypeInformation
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to construct a transact sql script that will stop specified people from
I have the following script that I want to insert into a table, but
here is the skeleton script that i am using: #!/usr/bin/env perl =head1 NAME webapp-1
I am trying to create a msbuild script that will compile and place a
When my install script recognizes that a file (log file) is not writable -
I'm trying to develop a bash build script for a Java project that will
I have a PHP script that will throw exceptions (e.g. cannot connect to server).
I need to develop a script using Wordpress PHP that will run with the
I want to develop a C# web application that will allow customers to go
I have developed tower of hanoi game in java script. Now, I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.