Scripts/FileSystem.ps1


function ExistsDirectory([string]$path)
{
    <#
    .SYNOPSIS
    Whether the given path is an existing directory.
    #>

    return [System.IO.Directory]::Exists($path)
}

function CreateDirectory([string]$path)
{
    <#
    .SYNOPSIS
    Creates a directory at the given path.
    #>

    [void][System.IO.Directory]::CreateDirectory($path)
}

function DeleteDirectory([string]$path)
{
    <#
    .SYNOPSIS
    Deletes a directory from the given path.
    #>

    [void][System.IO.Directory]::Delete($path, $true)
}


function GetCurrentDirectory()
{
    <#
    .SYNOPSIS
    Gets the current directory.
    #>

    return [System.IO.Directory]::GetCurrentDirectory()
}


function SetCurrentDirectory([string]$path)
{
    <#
    .SYNOPSIS
    Sets the current directory.
    #>

    [void][System.IO.Directory]::SetCurrentDirectory($path)
}


function ExistsFile([string]$path)
{
    <#
    .SYNOPSIS
    Whether a file exists at the given path.
    #>

    return [System.IO.File]::Exists($path)
}

function DeleteFile([string]$path)
{
    <#
    .SYNOPSIS
    Deletes the file at the given path.
    #>

    [void][System.IO.File]::Delete($path)
}

function ExistsPath([string]$path)
{
    <#
    .SYNOPSIS
    Whether a file or directory exists at the given path.
    #>

    return (ExistsDirectory $path) -Or (ExistsFile $path)
}

function GetLatestChangedFilesInFolder()
{
    <#
    .SYNOPSIS
    Gets the most recent changed files in the given target folder.
    #>

    
    param
    (
        [int]$changeCount,
        [string]$targetFolder,
        [string]$filter
    )
    
    $items = Get-ChildItem $targetFolder -Filter $filter -File -Recurse | `
        Sort-Object LastWriteTime -Descending | Select-Object -First $changeCount

    [array]$fileInfos = $items | Foreach-Object { @{
        Name = $_.Name; 
        LastWriteTime = $_.LastWriteTime;
        TimeSpanString = ((Get-Date) - $_.LastWriteTime)
    }}
    return $fileInfos
}