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 - get-date - make it a filename

Reply
 
Old 11-04-2008   #1 (permalink)
IT Staff


 
 

get-date - make it a filename


$WshShell = New-Object -ComObject WScript.Shell
$wshshell.run("winzip32 -m 'c:\$(Get-Date -format 'yyyy MMM d').zip'
$dir_source")

I would like my zip file to be "2008 nov 5.zip" ..however powershell zip the
file to "2008.zip"

How can i make the date as part of the file ?





My System SpecsSystem Spec
Old 11-05-2008   #2 (permalink)
Shay Levy [MVP]


 
 

Re: get-date - make it a filename

Hello IT,


Try this way:


$fileName = "C:\{0:yyyy MMM d}.zip" -f (get-date)
& winzip32 -m "$fileName" "$dir_source"




---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar


IS> $WshShell = New-Object -ComObject WScript.Shell
IS> $wshshell.run("winzip32 -m 'c:\$(Get-Date -format 'yyyy MMM d').zip'
IS> $dir_source")
IS>
IS> I would like my zip file to be "2008 nov 5.zip" ..however powershell
IS> zip the file to "2008.zip"
IS>
IS> How can i make the date as part of the file ?
IS>


My System SpecsSystem Spec
Old 11-05-2008   #3 (permalink)
IT Staff


 
 

Re: get-date - make it a filename

although $filename looks ok as a string, however

$wshshell.run("winzip32 -m $filename $dir_source") ==> still not able to
recognise full string of $filename.

How can i enscapulate $filename into the Run method ?




"Shay Levy [MVP]" <no@xxxxxx> wrote in message
news:89228ed2505868cb0d49a05a3a6a@xxxxxx
Quote:

> Hello IT,
>
>
> Try this way:
>
>
> $fileName = "C:\{0:yyyy MMM d}.zip" -f (get-date)
> & winzip32 -m "$fileName" "$dir_source"
>
>
>
>
> ---
> Shay Levy
> Windows PowerShell MVP
> http://blogs.microsoft.co.il/blogs/ScriptFanatic
> PowerShell Toolbar: http://tinyurl.com/PSToolbar
>
>
> IS> $WshShell = New-Object -ComObject WScript.Shell
> IS> $wshshell.run("winzip32 -m 'c:\$(Get-Date -format 'yyyy MMM d').zip'
> IS> $dir_source")
> IS> IS> I would like my zip file to be "2008 nov 5.zip" ..however
> powershell
> IS> zip the file to "2008.zip"
> IS> IS> How can i make the date as part of the file ?
> IS>
>

My System SpecsSystem Spec
Old 11-05-2008   #4 (permalink)
Rob Campbell


 
 

Re: get-date - make it a filename

I think the embedded spaces in the filename are messing with the parsing.

Try quoting the $filename, and escaping the quotes with backticks:

$wshshell.run("winzip32 -m `"$filename`" $dir_source")

I try to avoid using filenames with embedded spaces because it tends to
confuse the parser.

"IT Staff" wrote:
Quote:

> although $filename looks ok as a string, however
>
> $wshshell.run("winzip32 -m $filename $dir_source") ==> still not able to
> recognise full string of $filename.
>
> How can i enscapulate $filename into the Run method ?
>
>
>
>
> "Shay Levy [MVP]" <no@xxxxxx> wrote in message
> news:89228ed2505868cb0d49a05a3a6a@xxxxxx
Quote:

> > Hello IT,
> >
> >
> > Try this way:
> >
> >
> > $fileName = "C:\{0:yyyy MMM d}.zip" -f (get-date)
> > & winzip32 -m "$fileName" "$dir_source"
> >
> >
> >
> >
> > ---
> > Shay Levy
> > Windows PowerShell MVP
> > http://blogs.microsoft.co.il/blogs/ScriptFanatic
> > PowerShell Toolbar: http://tinyurl.com/PSToolbar
> >
> >
> > IS> $WshShell = New-Object -ComObject WScript.Shell
> > IS> $wshshell.run("winzip32 -m 'c:\$(Get-Date -format 'yyyy MMM d').zip'
> > IS> $dir_source")
> > IS> IS> I would like my zip file to be "2008 nov 5.zip" ..however
> > powershell
> > IS> zip the file to "2008.zip"
> > IS> IS> How can i make the date as part of the file ?
> > IS>
> >
>
>
>
My System SpecsSystem Spec
Old 11-05-2008   #5 (permalink)
IT Staff


 
 

Re: get-date - make it a filename

yes that is the backtick i m looking for ..thanks



"Rob Campbell" <RobCampbell@xxxxxx> wrote in message
news:C2469850-6802-4E6A-B27B-233081F7AAA3@xxxxxx
Quote:

>I think the embedded spaces in the filename are messing with the parsing.
>
> Try quoting the $filename, and escaping the quotes with backticks:
>
> $wshshell.run("winzip32 -m `"$filename`" $dir_source")
>
> I try to avoid using filenames with embedded spaces because it tends to
> confuse the parser.
>
> "IT Staff" wrote:
>
Quote:

>> although $filename looks ok as a string, however
>>
>> $wshshell.run("winzip32 -m $filename $dir_source") ==> still not able to
>> recognise full string of $filename.
>>
>> How can i enscapulate $filename into the Run method ?
>>
>>
>>
>>
>> "Shay Levy [MVP]" <no@xxxxxx> wrote in message
>> news:89228ed2505868cb0d49a05a3a6a@xxxxxx
Quote:

>> > Hello IT,
>> >
>> >
>> > Try this way:
>> >
>> >
>> > $fileName = "C:\{0:yyyy MMM d}.zip" -f (get-date)
>> > & winzip32 -m "$fileName" "$dir_source"
>> >
>> >
>> >
>> >
>> > ---
>> > Shay Levy
>> > Windows PowerShell MVP
>> > http://blogs.microsoft.co.il/blogs/ScriptFanatic
>> > PowerShell Toolbar: http://tinyurl.com/PSToolbar
>> >
>> >
>> > IS> $WshShell = New-Object -ComObject WScript.Shell
>> > IS> $wshshell.run("winzip32 -m 'c:\$(Get-Date -format 'yyyy MMM
>> > d').zip'
>> > IS> $dir_source")
>> > IS> IS> I would like my zip file to be "2008 nov 5.zip" ..however
>> > powershell
>> > IS> zip the file to "2008.zip"
>> > IS> IS> How can i make the date as part of the file ?
>> > IS>
>> >
>>
>>
>>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Modified Date used as Date Taken in Photo Gallery and Digital Imag Vista music pictures video
Photo date taken vs. file date Vista music pictures video
How do I make an end date for a recurring appointment in Calendar? Vista General
Add Date and time to filename 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