2014-06-17 22:15:18 +02:00
|
|
|
#!powershell
|
|
|
|
# WANT_JSON
|
2014-06-18 01:20:33 +02:00
|
|
|
# POWERSHELL_COMMON
|
2014-06-17 22:15:18 +02:00
|
|
|
|
2014-06-18 01:20:33 +02:00
|
|
|
$params = Parse-Args $args;
|
2014-06-17 22:15:18 +02:00
|
|
|
|
|
|
|
$path = '';
|
2014-06-17 22:44:53 +02:00
|
|
|
If ($params.path.GetType)
|
2014-06-17 22:15:18 +02:00
|
|
|
{
|
|
|
|
$path = $params.path;
|
|
|
|
}
|
|
|
|
|
|
|
|
$get_md5 = $TRUE;
|
2014-06-17 22:44:53 +02:00
|
|
|
If ($params.get_md5.GetType)
|
2014-06-17 22:15:18 +02:00
|
|
|
{
|
|
|
|
$get_md5 = $params.get_md5;
|
|
|
|
}
|
|
|
|
|
2014-06-17 22:44:06 +02:00
|
|
|
$stat = New-Object psobject;
|
2014-06-17 22:15:18 +02:00
|
|
|
If (Test-Path $path)
|
|
|
|
{
|
2014-06-18 01:20:33 +02:00
|
|
|
Set-Attr $stat "exists" $TRUE;
|
2014-06-17 22:15:18 +02:00
|
|
|
$info = Get-Item $path;
|
|
|
|
If ($info.Directory) # Only files have the .Directory attribute.
|
|
|
|
{
|
2014-06-18 01:20:33 +02:00
|
|
|
Set-Attr $stat "isdir" $FALSE;
|
|
|
|
Set-Attr $stat "size" $info.Length;
|
2014-06-17 22:15:18 +02:00
|
|
|
}
|
|
|
|
Else
|
|
|
|
{
|
2014-06-18 01:20:33 +02:00
|
|
|
Set-Attr $stat "isdir" $TRUE;
|
2014-06-17 22:15:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Else
|
|
|
|
{
|
2014-06-18 01:20:33 +02:00
|
|
|
Set-Attr $stat "exists" $FALSE;
|
2014-06-17 22:15:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
If ($get_md5 -and $stat.exists -and -not $stat.isdir)
|
|
|
|
{
|
|
|
|
$path_md5 = (Get-FileHash -Path $path -Algorithm MD5).Hash.ToLower();
|
2014-06-18 01:20:33 +02:00
|
|
|
Set-Attr $stat "md5" $path_md5;
|
2014-06-17 22:15:18 +02:00
|
|
|
}
|
|
|
|
|
2014-06-17 22:44:06 +02:00
|
|
|
$result = New-Object psobject;
|
2014-06-18 01:20:33 +02:00
|
|
|
Set-Attr $result "stat" $stat;
|
|
|
|
Set-Attr $result "changed" $FALSE;
|
2014-06-17 22:15:18 +02:00
|
|
|
echo $result | ConvertTo-Json;
|