-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorefile.ps1
64 lines (56 loc) · 1.78 KB
/
storefile.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Return a random datastore file.
function Get-RandomStoreFile {
# Get the file name and put it into an array
[System.Array]$arr = Get-ChildItem -Path ./store_file -Include @("*.txt") -Name
$count_arr = $arr.Count
if ($count_arr -ge 2) {
$num_select = Get-Random -Maximum $count_arr -Minimum 0
}
elseif ($count_arr -eq 1) {
$num_select = 0
}
else {
Write-ThereIsNoStoreFile
return
}
$selected = $arr[$num_select]
# $fullpath = $store_fileDir + $selected
# Write-Host "[store file]: $selected"
return $selected
}
function Get-Storefile {
# Select the data store file
$mode = Write-StorefileMode # ストアファイルのモード選択
if (($mode -eq 'r') -or ($mode -eq 'R')) {
# Set a random data store file
$storefilename = Get-RandomStoreFile
Write-Host "[store filename]: $storefilename"
}
elseif (($mode -eq 's') -or ($mode -eq 'S')) {
# Selecting and setting a data store file
$storefilename = Get-SelectStoreFile
Write-Host "[store filename]: $storefilename"
}
$filename_store = $store_fileDir + $storefilename
return $filename_store
}
# Return a string registered in a datastore file at random
function Get-RandomRegisteredStr($storefilename) {
# Read the registered contents from the file and put it into an array
$arr_file = Get-Content -LiteralPath $storefilename -Encoding UTF8
$count_arr = $arr_file.Count
if ($count_arr -ge 2) {
$num_select = Get-Random -Maximum $count_arr -Minimum 0
}
elseif ($count_arr -eq 1) {
$num_select = 0
}
else {
Write-ThereIsNoData
return
}
$selectstr = $arr_file[$num_select]
# Write-Host "[Get-RandomRegisteredStr]selectstr: $selectstr num_all: $count_arr ,num_select: $num_select"
Write-Host "[word selected]: $selectstr"
return $selectstr
}