4
# Microsoft Windows [Version 10.0.17134.648] 
# powershell 5.1.17134.48
# Calculate time to complete task using Notepad++ "backup on save" feature.  Create a copy and paste table of files sorted by LastWriteTime.    
# Can be used as a shortcut: powershell -noexit $time = (Get-Date).AddDays(-1); gci * -exclude _*, 1* | where {$_.LastWriteTime -gt $time}| sort -property LastWriteTime -descending | Format-Table LastWriteTime, length, @{n='foo';e={$_.Name -replace '(?<=^.*\.html).*$' -replace '(?<=^.*\.jpg).*$'}} -HideTableHeaders
# start it in %userprofile%\Documents\NOTEPAD++ AUTOBACKUP
Set-Location -Path "$env:userprofile\Documents\NOTEPAD++ AUTOBACKUP"
# how old a file? Today? 4 days old?
$time = (Get-Date).AddDays(-1)
# $time = (Get-Date).AddDays(-4)
# do you want to exclude files with -exclude? Do you want to include with -include?
gci * -exclude _*, 1* | where {$_.LastWriteTime -gt $time}| sort -property LastWriteTime -descending | Format-Table LastWriteTime, length, @{n='foo';e={$_.Name -replace '(?<=^.*\.html).*$' -replace '(?<=^.*\.jpg).*$'}} -HideTableHeaders
gci * -exclude _*, 1* | where {$_.LastWriteTime -gt $time} | sort -property LastWriteTime -descending | Format-Table LastWriteTime, length, Name -HideTableHeaders
# gci * | where {$_.LastWriteTime -gt $time} | sort -property LastWriteTime -descending | Format-Table LastWriteTime, length, @{n='foo';e={$_.Name -replace '(?<=^.*\.html).*$' -replace '(?<=^.*\.jpg).*$'}} -HideTableHeaders
# gci * -include [0-9][0-9][0-9]*, avail* | where {$_.LastWriteTime -gt $time} | sort -property LastWriteTime -descending | Format-Table LastWriteTime, length, @{n='foo';e={$_.Name -replace '(?<=^.*\.html).*$' -replace '(?<=^.*\.jpg).*$'}} -HideTableHeaders

outputs:

5/4/2019 10  :  47  :  27 AM  114036 springhill_falls2bd750_885.jpg
5/4/2019 10  :  45  :  25 AM 1301974 springhill_falls2bd750_885.psp
5/4/2019 10  :  37  :  08 AM   19268 springhill_falls2bd13.html
5/4/2019 10  :  37  :  08 AM   94007 available13.html
5/4/2019 10  :  37  :  08 AM   36729 index.html
5/4/2019 10  :  32  :  16 AM   62801 aj.php

and:

5/4/2019 10  :  47  :  27 AM  114036 springhill_falls2bd750_885.jpg.2019-05-04_104748.bak
5/4/2019 10  :  45  :  25 AM 1301974 springhill_falls2bd750_885.psp.2019-05-04_105221.bak
5/4/2019 10  :  37  :  08 AM   19268 springhill_falls2bd13.html.2019-05-04_105856.bak
5/4/2019 10  :  37  :  08 AM   94007 available13.html.2019-05-04_105657.bak
5/4/2019 10  :  37  :  08 AM   36729 index.html.2019-05-04_105657.bak
5/4/2019 10  :  32  :  16 AM   62801 aj.php.2019-05-04_103229.bak

Microsoft Windows [Version 10.0.17134.648]
powershell 5.1.17134.48

Calculate time to complete task using Notepad++ / NPP / Notepad Plus "backup on save" feature.

Create a copy and paste table of files sorted by LastWriteTime.

Can be used as a shortcut:

powershell -noexit $time = (Get-Date).AddDays(-1); gci * -exclude _*, 1* |
    where {$_.LastWriteTime -gt $time} | sort -property LastWriteTime -descending |
    Format-Table LastWriteTime, length, @{n='foo';e={$_.Name
    -replace '(?<=^.*\.html).*$' -replace '(?<=^.*\.jpg).*$'}} -HideTableHeaders

Start it in the directory where your NPP autobackup goes. My files are backed up to %userprofile%\Documents\NOTEPAD++ AUTOBACKUP

This script creates a formatted table output with the edited filenames, size, date and the time each time the file was written to. It is easy to modify which files to search for, how to edit the filenames and how many days old a file you want to search for. It is a convenient way to keep track of how long a file is worked on, how long a task took to complete, how long a project takes.

See LotPings answer below for information about the regex.

2 Answers 2

4

I'd use a RegEx with zero length lookbehind assertion to remove everything after html from $_.Name

This can be done with a calculated property either in a Select-Object or also in a Format-*

Get-ChildItem -File | 
  Format-Table @{n='foo';e={$_.Name -replace '(?<=^.*\.html).*$'}},Name -HideTableHeaders

Sample output:

available13.html available13.html.2019-03-26_081523.bak
index.html       index.html.2019-03-26_081538.bak
4

You can add a new property with Add-Member like this

$time = (Get-Date).AddDays(-4)
$files = gci * -include index*,avail* | where {$_.LastWriteTime -gt $time}
foreach ($f in $files) {
    $f | Add-Member noteproperty newName -Value `
             $f.Name.Substring(0, $f.Name.Length - ".yyyy-mm-dd_iiiiii.bak".Length)
}
$files | Format-Table -HideTableHeaders newName,Length,LastWriteTime

Note that the above snippet assumes that your names always end with .yyyy-mm-dd_iiiiii.bak. If they have some other format then you must include that information in the question, and you may need to use other string methods like replace, substring... to remove the unnecessary part

1
  • @LotPings I choose LotPings answer because it would have been the answer if I had asked a better question. Thanks for taking the time. Your code works.
    – somebadhat
    Commented Apr 4, 2019 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .