JhennSys
JhennSys

Reputation: 23

AWS PowerShell Error trying to use Substring() going through a $File array

Everything works except the Substring(). I want to use the left 10 bytes of the file name for the folder name to save the files in.

Error Msg: Method invocation failed because [System.IO.FileInfo] does not contain a method named 'Substring'.

PowerShell code:
$Filter = "*.SCNX"
$files = @(get-childitem  -path $OutBoxPath -filter $filter)
Write-Host 'File Count? ' $Files.count
foreach ($file in $files) {
Write-Host 'File ' $File
Write-Host $File.Substring(0,10)
}

Upvotes: 1

Views: 53

Answers (1)

mcbr
mcbr

Reputation: 781

Use $File.Name property to get the file name. System.IO.FileInfo is a class from .NET Framework and you can read about it in the docs

Upvotes: 1

Related Questions