Skip to content

Instantly share code, notes, and snippets.

@chestercodes
Created January 24, 2016 18:22
Show Gist options
  • Save chestercodes/05609733cf1cab6ca7c8 to your computer and use it in GitHub Desktop.
Save chestercodes/05609733cf1cab6ca7c8 to your computer and use it in GitHub Desktop.
Script for playing files from a folder matching a regex one by one.
function next()
{
$nextFilesDir = "SomeDirContainingNextAndNextHistoryFiles"
$nextFilePath = "$nextFilesDir\Next.txt"
$nextFileContent = Get-Content ($nextFilePath)
"Next file content is: '$nextFileContent'"
$filesDir = $nextFileContent[0].Replace("files-dir:", "")
$fileRegex = $nextFileContent[1].Replace("file-regex:", "")
$historyFilePath = "$nextFilesDir\Next-History.txt"
$history = Get-Content $historyFilePath
if($history -eq $null)
{
$history = @("")
}
$matchingFiles = Get-ChildItem $filesDir | Where-Object { $_.Name -match $fileRegex }
$firstNotOpened = $matchingFiles | Where-Object { $history.Contains( $_ ) -eq $false} | Select -First 1
if($firstNotOpened -eq $null) {
"There are no files left to open."
return
}
else {
"I have decided that the first not opened is $firstNotOpened"
}
$yesOrSomethingElse = Read-Host -Prompt "Enter 'y' to open $firstNotOpened"
if($yesOrSomethingElse.ToLower() -eq "y")
{
explorer.exe "$filesDir\$firstNotOpened"
}else {
return
}
$history += $firstNotOpened.Name
Set-Content $historyFilePath $history
}
files-dir:SomeDirOfFilesToOpen
file-regex:some|regex.+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment