-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathps-bates-enumerator-v4.ps1
47 lines (32 loc) · 1.25 KB
/
ps-bates-enumerator-v4.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
# By Andre Abadi
$file = "bates-file-list.txt"
# starting bits & info
echo "`nRecursive Document Enumerator by Andre Abadi.`n"
echo "Recurses this and all subdirectories"
echo " and lists all files with Bates numbers."
echo " EG: ABC.0001.0001.0001.pdf`n"
echo "Puts them in a file called '$($file)'"
echo " alongside this script.`n"
# ensure this script's executing directory is correct
$mydir = Get-Location
Set-Location -Path $mydir
# check if text file already exists
$exists = Test-Path "$($mydir)\$($file)"
if ($exists) {
echo "Overwriting old '$($file)'`n"
}
echo "The following files were found with Bates Numbers:"
echo "==================================================="
# main function
# recursively find all files in this and lower directories
Get-ChildItem -Recurse -File | `
# regex for only files with bates number at start
Where-Object {$_.Name -match '(.{3}\.\d{4}\.\d{4}\.\d{4})'} | `
# get those file names
Select-Object -ExpandProperty Name | `
# spit them out the command line as well as dumping to text file
Tee-Object -FilePath $file
# ending bits
echo "==================================================`n"
echo "Wrote to '$($file)`n"
Read-Host "Press ENTER to exit"