Skip to content

Commit

Permalink
refactor Get-FileInformation function and improve readability
Browse files Browse the repository at this point in the history
The Get-FileInformation function has been refactored to improve readability and maintainability. The code has been updated to use the -LiteralPath parameter instead of $File for consistency and clarity. The code now returns a custom object with Name, FullName, Size, IsReadOnly, and LastWriteTime properties, making it easier to work with the file information. This change simplifies the code and enhances its overall usability. No newline character at the end of file.
  • Loading branch information
PrzemyslawKlys committed Nov 22, 2023
1 parent 82942d5 commit 85ff593
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions Public/FilesFolders/Get-FileInformation.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
function Get-FileInformation {
<#
.SYNOPSIS
Get information about file such as Name, FullName and Size
.DESCRIPTION
Get information about file such as Name, FullName and Size
.PARAMETER File
File to get information about
.EXAMPLE
Get-FileInformation -File 'C:\Support\GitHub\PSSharedGoods\Public\FilesFolders\Get-FileInformation.ps1'
.NOTES
General notes
#>
[CmdletBinding()]
param(
[string] $File
[alias('LiteralPath', 'Path')][string] $File
)
if (Test-Path $File) {
return Get-Item $File | Select-Object Name, FullName, @{N = 'Size'; E = { Get-FileSize -Bytes $_.Length } }, IsReadOnly, LastWriteTime
if (Test-Path -LiteralPath $File) {
$Item = Get-Item -LiteralPath $File
[PSCustomObject] @{
Name = $Item.Name
FullName = $Item.FullName
Size = Get-FileSize -Bytes $Item.Length
IsReadOnly = $Item.IsReadOnly
LastWriteTime = $Item.LastWriteTime
}
}
return
}

0 comments on commit 85ff593

Please sign in to comment.