# do something with the file $file = Get-Item-Path$Path 'File {0} is of size {1} bytes.'-f$file.FullName, $file.Length }
Process-File-Path C:\windows\explorer.exe
结果看起来类似这样:
1 2 3 4 5
PS> Process-File-Path C:\windows\explorer.exe
File C:\windows\explorer.exe is of size 3903784 bytes.
PS>
这个函数每次只处理一个路径。如果希望传入多个路径,您需要这样做:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
functionProcess-File { param ( [string[]] $Path )
foreach($SinglePathin$Path) { # do something with the file $file = Get-Item-Path$SinglePath 'File {0} is of size {1} bytes.'-f$file.FullName, $file.Length } }
process { foreach($SinglePathin$Path) { # do something with the file $file = Get-Item-Path$SinglePath 'File {0} is of size {1} bytes.'-f$file.FullName, $file.Length } } }
process { foreach($SinglePathin$Path) { # do something with the file $file = Get-Item-Path$SinglePath 'File {0} is of size {1} bytes.'-f$file.FullName, $file.Length } } }