Created
January 24, 2016 18:22
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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