-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPSAlphaFS.ps1
79 lines (71 loc) · 2.72 KB
/
PSAlphaFS.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
##In Development
##Module will eventually emulate the functionality of the basic file system cmdlets in powershell using the AlphaFS classes to provide additional functionality
#region HelperModules
#Imports the AlphaFS modules. only here to save typing and make things look a bit cleaner
Function Import-AlphaModule{
try{
$scriptPath = (Split-Path ((Get-Variable MyInvocation -Scope Script).Value.MyCommand.Path))
Import-Module "$scriptPath\dll\Alphafs.dll"
}catch{
Import-Module ".\dll\AlphaFS.dll"
}
}
#endregion
#Will Emulate the copy-item command, currently basic file and directory copy's are implemented with the option to force
Function Copy-ItemAlpha{
[cmdletbinding()]
param(
[parameter(Mandatory=$true,Position=1,ValueFromPipeline=$true)]
$sourceFile,
[parameter(Mandatory=$true,Position=2)]
$destinationFile,
[parameter(Mandatory=$false)]
[switch]$force=$false
)
Import-AlphaModule
if([Alphaleonis.Win32.Filesystem.File]::Exists($sourceFile)){
[Alphaleonis.Win32.Filesystem.File]::Copy($sourceFile,$destinationFile,"overwrite=$force")
}
if([Alphaleonis.Win32.Filesystem.Directory]::Exists($sourceFile)){
[Alphaleonis.Win32.Filesystem.Directory]::Copy($sourceFile,$destinationFile,"overwrite=$force")
}
}
#Will Emulate Remove-Item, currently basic file and directory delete's are implemented with a force option
Function Remove-ItemAlpha {
[cmdletbinding()]
param(
[parameter(Mandatory=$true,Position=1,ValueFromPipeline=$true)]
$Path,
[parameter(Mandatory=$False)]
[switch]$force=$false,
[parameter(Mandatory=$false)]
[switch]$recurse=$false
)
Import-AlphaModule
if([Alphaleonis.Win32.Filesystem.File]::Exists($path)){
[Alphaleonis.Win32.Filesystem.File]::Delete($path,"ignorereadonly=$force")
}
if([Alphaleonis.Win32.Filesystem.Directory]::Exists($path)){
[Alphaleonis.Win32.Filesystem.Directory]::Delete($path,"ignorereadonly=$force","recursive=$recurse")
}
}
Function Get-ItemAlpha{
param(
[parameter(Mandatory=$true,Position=1,ValueFromPipeline=$true)]
$Path
)
Import-AlphaModule
if([Alphaleonis.Win32.Filesystem.File]::Exists($path)){
$return = New-Object Alphaleonis.Win32.Filesystem.FileInfo($Path)
}
if([Alphaleonis.Win32.Filesystem.Directory]::Exists($path)){
$return = New-Object Alphaleonis.Win32.Filesystem.DirectoryInfo($Path)
}
return $return
}
#Using These will allow the helper functions to be hidden
<#
Export-ModuleMember Copy-ItemAlpha
Export-ModuleMember Remove-ItemAlpha
Export-ModuleMember Get-ItemAlpha
#>