hello,
I've been trying to read contents of few files in a directory where the file names are unusual. The file names contains multiple periods, curve braces and even hyphens. I tried via a script but received and error.
Say I got 3 files in a directory C:\Test
1. a.b.c.txt
2. this is my.file.new.txt
3 this is my.file.new.txt (2)
SAMPLE SCRIPT
--------------------------------------------------------------
$MyFileList = (Get-Content C:\Test).Name
foreach($file in $MyfileList) {Get-Content -path "C:\Test\$MyFileList"}
--------------------------------------------------------------
The above throws error
get-content : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
At line:1 char:1
+ get-content -Path C:\Test\$file
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (C:\Test:String) [Get-Content], PathTooLongException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetContentCommand
Any help on this will be highly appreciated.
Thanks in advance.