Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Problems working with Japanese characters found in filenames to determine invalid shortcuts

$
0
0

Hi,

I have written a script that uses test-path to query whether or not *.LNK shortcut files have valid Target Paths to determine whether or not the LNK files should be kept if invalid or contain temporary locations. This works perfectly for most shortcuts with the exception of those with filenames in Japanese/Chinese/Cyrillic fonts.

The script is made up of the following action:-

gci "$nextdrive\Users\$env:username\AppData\Roaming\microsoft\office\recent" -Filter *.lnk | % { $shell.CreateShortcut( $_.FullName ) } | ? { ( Test-Path ( $_.TargetPath )) -eq $false -or $_.TargetPath -like '*temporary internet files*' -or $_.TargetPath -like '*temp*'} | % { Remove-item -LiteralPath $_.FullName }

If I run the script when a file name exists in the folder above such as : 1、目录.doc.LNK

the Powershell script from the ISE returns the following error:-

"Cannot bind argument to parameter 'Path' because it is an empty string.

If I rename the .LNK file to something like 12345.doc.LNK, the powershell script successfully removes the file so I know that the issue is certainly related to the actual filename itself. Is there any sort of UTF, CJK or encoding option I need to configure here for this to work successfully?

Thanks for taking the time to read this!

Andrew


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>