![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Time: I've written a simple script to look for files older than (x) and move them to a new location and append the file name. Testing through the script I had it all working and now all of a sudden the minutes, seconds, and hours that I pull out to use in the log renaming arent displaying... only the day/month/year variables print out. I've added some extra lines in order for it to print out the results to my screen instead of moving the files so you'll see the move commented out in the current version. Anyone see why min/sec/hours isnt catching a variable all of a sudden. I don't believe I've changed any thing. $path = "c:\etc\blah\cache\" $backuppath = "c:\temp\blah\backup\" $compare = (Get-Date).AddDays(-1) ForEach($folder in $path) { $oldfolder = Get-ChildItem $folder | where-object {$_.lastwritetime -lt $compare} ForEach ($moveme in $oldfolder) { [string]$mo = $moveme.lastwritetime.Month [string]$day = $moveme.lastwritetime.Day [string]$yr = $moveme.lastwritetime.Year [string]$hr = $moveme.lastwritetime.Hours [string]$sec = $moveme.lastwritetime.Seconds [string]$min = $moveme.lastwritetime.Minutes if ($mo.length -lt 2) {$mo="0"+$mo} if ($day.length -lt 2) {$day="0"+$day} $fulldate = $yr += $mo += $day += $hr += $min += $sec $fulldate #Move-Item "$path$moveme" "$backuppath$moveme.$fulldate" } } |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Time: Also, sorry, the output is: 20080904 I am looking for something more like: 200809040522203 "Jason Roberson" wrote: Quote: > I've written a simple script to look for files older than (x) and move them > to a new location and append the file name. Testing through the script I had > it all working and now all of a sudden the minutes, seconds, and hours that I > pull out to use in the log renaming arent displaying... only the > day/month/year variables print out. > > I've added some extra lines in order for it to print out the results to my > screen instead of moving the files so you'll see the move commented out in > the current version. Anyone see why min/sec/hours isnt catching a variable > all of a sudden. I don't believe I've changed any thing. > > $path = "c:\etc\blah\cache\" > $backuppath = "c:\temp\blah\backup\" > $compare = (Get-Date).AddDays(-1) > > > ForEach($folder in $path) > { > > $oldfolder = Get-ChildItem $folder | where-object {$_.lastwritetime -lt > $compare} > > ForEach ($moveme in $oldfolder) > > { > > [string]$mo = $moveme.lastwritetime.Month > [string]$day = $moveme.lastwritetime.Day > [string]$yr = $moveme.lastwritetime.Year > [string]$hr = $moveme.lastwritetime.Hours > [string]$sec = $moveme.lastwritetime.Seconds > [string]$min = $moveme.lastwritetime.Minutes > > if ($mo.length -lt 2) {$mo="0"+$mo} > if ($day.length -lt 2) {$day="0"+$day} > > $fulldate = $yr += $mo += $day += $hr += $min += $sec > $fulldate > > #Move-Item "$path$moveme" "$backuppath$moveme.$fulldate" > > } > > } > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Time: By the way, you can save yourself many lines of code if you generate your ISO8601 date string in $fulldate like this: $moveme.lastwritetime.ToString("yyyyMMddHHmmss") That will give you correct formatting with leading zeroes where needed for padding. "Jason Roberson" <Jason Roberson@xxxxxx> wrote in message news:5674F4C6-BBFA-4623-84E0-CCBDA8CA0789@xxxxxx Quote: > I've written a simple script to look for files older than (x) and move > them > to a new location and append the file name. Testing through the script I > had > it all working and now all of a sudden the minutes, seconds, and hours > that I > pull out to use in the log renaming arent displaying... only the > day/month/year variables print out. > > I've added some extra lines in order for it to print out the results to my > screen instead of moving the files so you'll see the move commented out in > the current version. Anyone see why min/sec/hours isnt catching a > variable > all of a sudden. I don't believe I've changed any thing. > > $path = "c:\etc\blah\cache\" > $backuppath = "c:\temp\blah\backup\" > $compare = (Get-Date).AddDays(-1) > > > ForEach($folder in $path) > { > > $oldfolder = Get-ChildItem $folder | where-object {$_.lastwritetime -lt > $compare} > > ForEach ($moveme in $oldfolder) > > { > > [string]$mo = $moveme.lastwritetime.Month > [string]$day = $moveme.lastwritetime.Day > [string]$yr = $moveme.lastwritetime.Year > [string]$hr = $moveme.lastwritetime.Hours > [string]$sec = $moveme.lastwritetime.Seconds > [string]$min = $moveme.lastwritetime.Minutes > > if ($mo.length -lt 2) {$mo="0"+$mo} > if ($day.length -lt 2) {$day="0"+$day} > > $fulldate = $yr += $mo += $day += $hr += $min += $sec > $fulldate > > #Move-Item "$path$moveme" "$backuppath$moveme.$fulldate" > > } > > } > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Time: I was unser about that, thank you for filling me in on that Alex! "Alex K. Angelopoulos" wrote: Quote: > By the way, you can save yourself many lines of code if you generate your > ISO8601 date string in $fulldate like this: > > $moveme.lastwritetime.ToString("yyyyMMddHHmmss") > > That will give you correct formatting with leading zeroes where needed for > padding. > > > "Jason Roberson" <Jason Roberson@xxxxxx> wrote in message > news:5674F4C6-BBFA-4623-84E0-CCBDA8CA0789@xxxxxx Quote: > > I've written a simple script to look for files older than (x) and move > > them > > to a new location and append the file name. Testing through the script I > > had > > it all working and now all of a sudden the minutes, seconds, and hours > > that I > > pull out to use in the log renaming arent displaying... only the > > day/month/year variables print out. > > > > I've added some extra lines in order for it to print out the results to my > > screen instead of moving the files so you'll see the move commented out in > > the current version. Anyone see why min/sec/hours isnt catching a > > variable > > all of a sudden. I don't believe I've changed any thing. > > > > $path = "c:\etc\blah\cache\" > > $backuppath = "c:\temp\blah\backup\" > > $compare = (Get-Date).AddDays(-1) > > > > > > ForEach($folder in $path) > > { > > > > $oldfolder = Get-ChildItem $folder | where-object {$_.lastwritetime -lt > > $compare} > > > > ForEach ($moveme in $oldfolder) > > > > { > > > > [string]$mo = $moveme.lastwritetime.Month > > [string]$day = $moveme.lastwritetime.Day > > [string]$yr = $moveme.lastwritetime.Year > > [string]$hr = $moveme.lastwritetime.Hours > > [string]$sec = $moveme.lastwritetime.Seconds > > [string]$min = $moveme.lastwritetime.Minutes > > > > if ($mo.length -lt 2) {$mo="0"+$mo} > > if ($day.length -lt 2) {$day="0"+$day} > > > > $fulldate = $yr += $mo += $day += $hr += $min += $sec > > $fulldate > > > > #Move-Item "$path$moveme" "$backuppath$moveme.$fulldate" > > > > } > > > > } > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Windows System Time and Desktop time not matching up | Vista General | |||
| Changing the time zone changes the appointment time in calendar | .NET General | |||
| Internet Time Synchronization Incorrect - Showing Standard Time | PowerShell | |||
| One question about Windows Time Synchronize with Internet Time Ser | Vista General | |||
| Demo of getting/setting time from an RFC867 time source | PowerShell | |||