![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Passing filename as parameter I have a script which tests if a file/path exists and moves an item if it does. However whenever my file\path contains a bracket [] commas , etc the test file path comes up that it doesn't exist even though it does. How can I overcome this problem? Is there a way of passing the filename as a parameter? This is the code I'm working with: $filename = $args[0] $destination = "C:\powershell" [string]$fileexist = Test-Path -Path $filename If ($fileexist -eq "False") { #Sends E-mail to notify me that file doesn't exist exit } Else { copy-item $filename -destination $destination } Command line I run: ..\test.ps1 "\C:\Done\a509054_MIC_0109[1].jpg" Any help will be appreciated. Thanks, Anthony |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Passing filename as parameter On Sep 27, 2:15 pm, anth <a...@xxxxxx> wrote:
in path names. This is probably the closest to the situation you are seeing: https://connect.microsoft.com/feedba...1307&SiteID=99 You can vote to have it fixed in a later version. Until then, use the LiteralPath parameter of the Test-Path Cmdlet: [string]$fileexist = Test-Path -LiteralPath $filename Jeff | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) |
| Guest | Re: Passing filename as parameter You can double escape each bracket in the file's path: ..\test.ps1 "\C:\Done\a509054_MIC_0109``[1``].jpg" -- Kiron |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Passing filename as parameter You could let the script double escape the brackets: # -- test.ps1 -- $filename = $args[0] -replace '[\[\]]', '``$0' $destination = "C:\powershell" [string]$fileexist = Test-Path -Path $filename If ($fileexist -eq "False") { #Sends E-mail to notify me that file doesn't exist "absent" exit } Else { copy-item $filename -destination $destination } -- Kiron |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Invoke-Expression parameter Passing | James | PowerShell | 4 | 11-02-2007 03:44 AM |
| Passing a string array as a parameter from one script to another | Brillig | PowerShell | 5 | 09-27-2007 04:16 AM |
| Function Parameter passing wrong or am I ? | joergH | PowerShell | 4 | 01-23-2007 05:16 PM |
| Problem with parameter passing? | =?Utf-8?B?TWF0dA==?= | PowerShell | 3 | 10-06-2006 04:35 PM |
| Passing parameter from one Page to another | Johann MacDonagh | Avalon | 3 | 04-10-2006 05:01 PM |