Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

removing selected file that contain special characters

Closed Thread
 
Thread Tools Display Modes
Old 12-02-2006   #1 (permalink)
Paul
Guest


 

removing selected file that contain special characters

I had posted this on the windows.server.scripting newsgroup before realising
that there was a powershell newsgroup. Can anyone help?

How can I remove selected files that have special characters in it's name?
I'm trying to remove old cookies. I can list them using

gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)}

but if I then try to delete them

gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)} | rm

it fails to remove any files. The files are cookies and have file names like
user@a.site.com[2].txt

If i run the command "gci | rm" from a folder that contains some cookie
files and other files, only the files without special characters gets deleted.

Any help appreciated.

Old 12-02-2006   #2 (permalink)
dreeschkind
Guest


 

RE: removing selected file that contain special characters

Square brackets are used as wildcard characters similar to "*" and "?".
Thus, you sometimes need to use the -LiteralPath parameter for certain
cmdlets when dealing with such path names. However, I thought that the
literal interpretation is default when a path is piped into the cmdlet. Maybe
this is a bug (there are some more problems like this in version 1).
Does the following workaround delete those files?

gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)}
| foreach-object { rm -literalpath $_ }

--
greetings
dreeschkind

"Paul" wrote:

> I had posted this on the windows.server.scripting newsgroup before realising
> that there was a powershell newsgroup. Can anyone help?
>
> How can I remove selected files that have special characters in it's name?
> I'm trying to remove old cookies. I can list them using
>
> gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)}
>
> but if I then try to delete them
>
> gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)} | rm
>
> it fails to remove any files. The files are cookies and have file names like
> user@a.site.com[2].txt
>
> If i run the command "gci | rm" from a folder that contains some cookie
> files and other files, only the files without special characters gets deleted.
>
> Any help appreciated.
>

Old 12-02-2006   #3 (permalink)
Paul
Guest


 

RE: removing selected file that contain special characters

When I try to run the code below I get the error:

Remove-Item : A parameter cannot be found that matches parameter name
'Literalpath'.

I am running powershell version 1.0.9567.1 . Has the Literalpath been
introduced in a newer version?

Thanks for your quick response dreeschkind
Paul.



"dreeschkind" wrote:

> Square brackets are used as wildcard characters similar to "*" and "?".
> Thus, you sometimes need to use the -LiteralPath parameter for certain
> cmdlets when dealing with such path names. However, I thought that the
> literal interpretation is default when a path is piped into the cmdlet. Maybe
> this is a bug (there are some more problems like this in version 1).
> Does the following workaround delete those files?
>
> gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)}
> | foreach-object { rm -literalpath $_ }
>
> --
> greetings
> dreeschkind
>
> "Paul" wrote:
>
> > I had posted this on the windows.server.scripting newsgroup before realising
> > that there was a powershell newsgroup. Can anyone help?
> >
> > How can I remove selected files that have special characters in it's name?
> > I'm trying to remove old cookies. I can list them using
> >
> > gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)}
> >
> > but if I then try to delete them
> >
> > gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)} | rm
> >
> > it fails to remove any files. The files are cookies and have file names like
> > user@a.site.com[2].txt
> >
> > If i run the command "gci | rm" from a folder that contains some cookie
> > files and other files, only the files without special characters gets deleted.
> >
> > Any help appreciated.
> >

Old 12-02-2006   #4 (permalink)
RichS
Guest


 

RE: removing selected file that contain special characters

The RTM version shows version 1.0.0.0

Did you update to the RTM version?

Can download from here

http://www.microsoft.com/windowsserv.../download.mspx
--
Richard Siddaway

Please note that all scripts are supplied "as is" and with no warranty


"Paul" wrote:

> When I try to run the code below I get the error:
>
> Remove-Item : A parameter cannot be found that matches parameter name
> 'Literalpath'.
>
> I am running powershell version 1.0.9567.1 . Has the Literalpath been
> introduced in a newer version?
>
> Thanks for your quick response dreeschkind
> Paul.
>
>
>
> "dreeschkind" wrote:
>
> > Square brackets are used as wildcard characters similar to "*" and "?".
> > Thus, you sometimes need to use the -LiteralPath parameter for certain
> > cmdlets when dealing with such path names. However, I thought that the
> > literal interpretation is default when a path is piped into the cmdlet. Maybe
> > this is a bug (there are some more problems like this in version 1).
> > Does the following workaround delete those files?
> >
> > gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)}
> > | foreach-object { rm -literalpath $_ }
> >
> > --
> > greetings
> > dreeschkind
> >
> > "Paul" wrote:
> >
> > > I had posted this on the windows.server.scripting newsgroup before realising
> > > that there was a powershell newsgroup. Can anyone help?
> > >
> > > How can I remove selected files that have special characters in it's name?
> > > I'm trying to remove old cookies. I can list them using
> > >
> > > gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)}
> > >
> > > but if I then try to delete them
> > >
> > > gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)} | rm
> > >
> > > it fails to remove any files. The files are cookies and have file names like
> > > user@a.site.com[2].txt
> > >
> > > If i run the command "gci | rm" from a folder that contains some cookie
> > > files and other files, only the files without special characters gets deleted.
> > >
> > > Any help appreciated.
> > >

Old 12-02-2006   #5 (permalink)
dreeschkind
Guest


 

RE: removing selected file that contain special characters

Richard is correct, your version looks like PowerShell RC1.
The LiteralPath workaround has been introduced with RC2.

See the following section on the PowerShell blog:
"Access files and directories with special character names"
http://blogs.msdn.com/powershell/arc...se-Notes-.aspx

--
greetings
dreeschkind

"Paul" wrote:

> When I try to run the code below I get the error:
>
> Remove-Item : A parameter cannot be found that matches parameter name
> 'Literalpath'.
>
> I am running powershell version 1.0.9567.1 . Has the Literalpath been
> introduced in a newer version?
>
> Thanks for your quick response dreeschkind
> Paul.
>
>
>
> "dreeschkind" wrote:
>
> > Square brackets are used as wildcard characters similar to "*" and "?".
> > Thus, you sometimes need to use the -LiteralPath parameter for certain
> > cmdlets when dealing with such path names. However, I thought that the
> > literal interpretation is default when a path is piped into the cmdlet. Maybe
> > this is a bug (there are some more problems like this in version 1).
> > Does the following workaround delete those files?
> >
> > gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)}
> > | foreach-object { rm -literalpath $_ }
> >
> > --
> > greetings
> > dreeschkind
> >
> > "Paul" wrote:
> >
> > > I had posted this on the windows.server.scripting newsgroup before realising
> > > that there was a powershell newsgroup. Can anyone help?
> > >
> > > How can I remove selected files that have special characters in it's name?
> > > I'm trying to remove old cookies. I can list them using
> > >
> > > gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)}
> > >
> > > but if I then try to delete them
> > >
> > > gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)} | rm
> > >
> > > it fails to remove any files. The files are cookies and have file names like
> > > user@a.site.com[2].txt
> > >
> > > If i run the command "gci | rm" from a folder that contains some cookie
> > > files and other files, only the files without special characters gets deleted.
> > >
> > > Any help appreciated.
> > >

Old 12-03-2006   #6 (permalink)
Paul
Guest


 

RE: removing selected file that contain special characters

Thank you both for your replies. I didn't realised that the old version was
installed. I have tested this using version 1 and it works fine. I assumed
the host version greater than 1.0 ment I had the new version :-(

Paul.

"dreeschkind" wrote:

> Richard is correct, your version looks like PowerShell RC1.
> The LiteralPath workaround has been introduced with RC2.
>
> See the following section on the PowerShell blog:
> "Access files and directories with special character names"
> http://blogs.msdn.com/powershell/arc...se-Notes-.aspx
>
> --
> greetings
> dreeschkind
>
> "Paul" wrote:
>
> > When I try to run the code below I get the error:
> >
> > Remove-Item : A parameter cannot be found that matches parameter name
> > 'Literalpath'.
> >
> > I am running powershell version 1.0.9567.1 . Has the Literalpath been
> > introduced in a newer version?
> >
> > Thanks for your quick response dreeschkind
> > Paul.
> >
> >
> >
> > "dreeschkind" wrote:
> >
> > > Square brackets are used as wildcard characters similar to "*" and "?".
> > > Thus, you sometimes need to use the -LiteralPath parameter for certain
> > > cmdlets when dealing with such path names. However, I thought that the
> > > literal interpretation is default when a path is piped into the cmdlet. Maybe
> > > this is a bug (there are some more problems like this in version 1).
> > > Does the following workaround delete those files?
> > >
> > > gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)}
> > > | foreach-object { rm -literalpath $_ }
> > >
> > > --
> > > greetings
> > > dreeschkind
> > >
> > > "Paul" wrote:
> > >
> > > > I had posted this on the windows.server.scripting newsgroup before realising
> > > > that there was a powershell newsgroup. Can anyone help?
> > > >
> > > > How can I remove selected files that have special characters in it's name?
> > > > I'm trying to remove old cookies. I can list them using
> > > >
> > > > gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)}
> > > >
> > > > but if I then try to delete them
> > > >
> > > > gci | where {$_.lastwritetime -le [datetime]::now.adddays(-60)} | rm
> > > >
> > > > it fails to remove any files. The files are cookies and have file names like
> > > > user@a.site.com[2].txt
> > > >
> > > > If i run the command "gci | rm" from a folder that contains some cookie
> > > > files and other files, only the files without special characters gets deleted.
> > > >
> > > > Any help appreciated.
> > > >

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Desktop Search and special characters doraz Vista file management 0 08-01-2008 04:22 PM
Typing in special characters bug Spart Vista General 1 02-15-2008 01:21 PM
Special Characters - how? euroeddie Vista General 6 04-24-2007 08:38 PM
How to run program with special characters marc PowerShell 4 03-05-2007 03:22 PM
Using Paths with Special Characters and/or Spaces public.microsoft.com PowerShell 5 08-06-2006 12:22 PM








Vistax64.com 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 2005-2008

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 47 48 49 50