Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Time:

Reply
 
Old 09-05-2008   #1 (permalink)
Jason Roberson


 
 

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 SpecsSystem Spec
Old 09-05-2008   #2 (permalink)
Jason Roberson


 
 

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 SpecsSystem Spec
Old 09-05-2008   #3 (permalink)
Alex K. Angelopoulos


 
 

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 SpecsSystem Spec
Old 09-08-2008   #4 (permalink)
Jason Roberson


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46