Skip to content

Commit 20e9074

Browse files
alievertzAndy Lievertz
andauthored
Added Get-OZOFileIsLocked; minor bugs and documentation updates; v1.1.0
* Added Get-OZOFileIsLocked; minor bugs and documentation updates; v1.1.0 --------- Co-authored-by: Andy Lievertz <alievertz@onezeroone.dev>
1 parent 5e1c92b commit 20e9074

7 files changed

Lines changed: 103 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
|Date|Version|Comment|
44
|----|-------|-------|
5+
|2025-Jun-01|1.1.0|Added `Get-OZOFileIsLocked`; minor bugs and documentation updates.|
56
|2025-May-19|1.0.0|Initial release including `Get-OZODirectorySummary`.|
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Get-OZOFileIsLocked
2+
This function is part of the [OZOFiles PowerShell Module](../README.md).
3+
4+
## Description
5+
Returns _True_ if the Path is locked or _False_ if the path is not locked, does not exist, is not accessible, or is a directory.
6+
7+
## Syntax
8+
```
9+
Get-OZOFileIsLocked
10+
-Path <String>
11+
```
12+
13+
## Parameters
14+
|Parameter|Description|
15+
|---------|-----------|
16+
|`Path`|The path of the file to inspect.|
17+
18+
## Examples
19+
```powershell
20+
Get-OZOFileIsLocked -Path "C:\Temp\test.txt"
21+
False
22+
```
23+
24+
## Outputs
25+
`System.Boolean`

Documentation/OZODirectorySummary.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# OZODirectorySummary Class
2-
This class is part of the [OZOFiles PowerShell Module](../README.md). Calling the `Get-OZODirectorySummary` function returns an object of the `OZODirectorySummary` class.
2+
This class is part of the [OZOFiles PowerShell Module](../README.md).
33

4+
## Usage
5+
Use the [`Get-OZODirectorySummary`](Get-OZODirectorySummary.md) function to return an object of this class.
6+
7+
## Definition
8+
### Associations
49
```
510
+ $Validates:Boolean = $true
611
+ $newestChildWriteTime:DateTime = (Get-Date -Year 1970 -Month 01 -Day 01 -Hour 00 -Minute 00 -Second 00)
@@ -11,8 +16,9 @@ This class is part of the [OZOFiles PowerShell Module](../README.md). Calling th
1116
+ $longPaths:System.Collections.Generic.List[System.IO.FileSystemInfo] = @()
1217
+ $problemPaths:System.Collections.Generic.List[System.IO.FileSystemInfo] = @()
1318
```
14-
---
19+
### Operations
1520
```
1621
+ OZODirectorySummary($LongLength,$Path):void
1722
- ValidateEnvironment():Boolean
1823
- GetDirectorySummary():Boolean
24+
```

Documentation/Test-OZOPath.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,28 @@ Determines if a path exists and is readable. Optionally tests if the path is wri
77
## Syntax
88
```
99
Test-OZOPath
10-
-Path <String>
10+
-Path <String>
11+
-Writable <Switch>
1112
```
1213

1314
## Parameters
1415
|Parameter|Description|
1516
|---------|-----------|
16-
|`Path`|The path to test. Returns TRUE if the path exists and is readable and otherwise returns FALSE.|
17-
|`Writable`|Determines if the path is writable. Returns TRUE if the path is writable and otherwise returns FALSE.|
17+
|`Path`|The path to test. Returns _True_ if the path exists and is readable and otherwise returns _False_.|
18+
|`Writable`|Determines if the path is writable. Returns _True_ if the path is writable and otherwise returns _False_.|
1819

1920
## Examples
21+
### Example 1
2022
```powershell
21-
Test-OZOPath -Path ".\README.md"
23+
Test-OZOPath -Path "C:\Windows\notepad.exe"
2224
True
2325
```
2426

27+
### Example 2
28+
```powershell
29+
Test-OZOPath -Path "C:\Windows\notepad.exe" -Writable
30+
False
31+
```
32+
2533
## Outputs
2634
`System.Boolean`

OZOFiles/OZOFiles.psd1

64 Bytes
Binary file not shown.

OZOFiles/OZOFiles.psm1

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,50 @@ Function Get-OZODirectorySummary {
160160
return [OZODirectorySummary]::new($LongLength,$Path)
161161
}
162162

163+
Function Get-OZOFileIsLocked {
164+
<#
165+
.SYNOPSIS
166+
See description.
167+
.DESCRIPTION
168+
Returns True if the Path is locked or False if the path is not locked, does not exist, is not accessible, is read-only, or is a directory.
169+
.PARAMETER Path
170+
The path of the file to inspect.
171+
.EXAMPLE
172+
Get-OZOFileIsLocked -Path "C:\Temp\test.txt"
173+
False
174+
.LINK
175+
https://github.com/onezeroone-dev/OZOFiles-PowerShell-Module/blob/main/Documentation/Get-OZOFileIsLocked.md
176+
#>
177+
# Parameters
178+
[CmdletBinding()] Param(
179+
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)][Alias("FullName","PSPath")][String[]]$Path
180+
)
181+
# Try to get the item
182+
Try {
183+
$Item = (Get-Item -Path $Path -ErrorAction Stop)
184+
# Success; determine if Item is a file
185+
If ($Item.PSIsContainer -eq $false) {
186+
# Item is a file; try to open it
187+
Try {
188+
$fileStream = [System.IO.File]::Open($Item.FullName,"Open","Write")
189+
$fileStream.Close()
190+
$fileStream.Dispose()
191+
# Success
192+
return $false
193+
} Catch {
194+
# Failure
195+
return $true
196+
}
197+
} Else {
198+
# Item is a directory
199+
return $false
200+
}
201+
} Catch {
202+
# Failure
203+
return $false
204+
}
205+
}
206+
163207
Function Get-OZOFileToBase64 {
164208
<#
165209
.SYNOPSIS
@@ -235,8 +279,11 @@ Function Test-OZOPath {
235279
.PARAMETER Writable
236280
Determines if the path is writable. Returns TRUE if the path is writable and otherwise returns FALSE.
237281
.EXAMPLE
238-
Test-OZOPath -Path .\README.md
282+
Test-OZOPath -Path "C:\Windows\notepad.exe"
239283
True
284+
.EXAMPLE
285+
Test-OZOPath -Path "C:\Windows\notepad.exe" -Writable
286+
False
240287
.LINK
241288
https://github.com/onezeroone-dev/OZOFiles-PowerShell-Module/blob/main/Documentation/Test-OZOPath.md
242289
#>
@@ -288,4 +335,4 @@ Function Test-OZOPath {
288335
}
289336
}
290337

291-
Export-ModuleMember -Function Get-OZOChildWriteTime,Get-OZODirectorySummary,Get-OZOFileToBase64,Set-OZOBase64ToFile,Test-OZOPath
338+
Export-ModuleMember -Function Get-OZOChildWriteTime,Get-OZODirectorySummary,Get-OZOFileIsLocked,Get-OZOFileToBase64,Set-OZOBase64ToFile,Test-OZOPath

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ Import-Module OZOFiles
1717
## Functions
1818

1919
- [Get-OZOChildWriteTime](Documentation/Get-OZOChildWriteTime.md)
20+
- [Get-OZODirectorySummary](Documentation/Get-OZODirectorySummary.md)
21+
- [Get-OZOFileIsLocked](Documentation/Get-OZOFileIsLocked.md)
2022
- [Get-OZOFileToBase64](Documentation/Get-OZOFileToBase64.md)
2123
- [Set-OZOBase64ToFile](Documentation/Set-OZOBase64tofile.md)
2224
- [Test-OZOPath](Documentation/Test-OZOPath.md)
2325

2426
## Classes
2527

2628
- [OZODirectorySummary](Documentation/OZODirectorySummary.md)
29+
30+
## License
31+
This module is licensed under the [GNU General Public License (GPL) version 2.0](LICENSE).
32+
33+
## Acknowledgements
34+
Special thanks to my employer, [Sonic Healthcare USA](https://sonichealthcareusa.com), who supports the growth of my PowerShell skillset and enables me to contribute portions of my work product to the PowerShell community.

0 commit comments

Comments
 (0)