-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreategamelist.py
More file actions
executable file
·45 lines (38 loc) · 1.37 KB
/
creategamelist.py
File metadata and controls
executable file
·45 lines (38 loc) · 1.37 KB
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
#!/usr/bin/env python3
import os
import arghelper
from pathlib import Path
from datetime import datetime
rompath: Path = arghelper.get_rompath()
gamefile: Path = arghelper.get_gameslist()
date = datetime.today().strftime("%d-%m-%Y")
def main():
try:
if gamefile.is_file():
print(f"There's already a {gamefile}-file, do you want to make a backup of it?")
answer = input("Y/N?\n").upper()
while(answer != "Y" and answer != "N"):
print("Only accepting Y for yes and N for no.")
answer = input("Y/N?\n")
if(answer == "Y"):
# Rename the old file with current date appended to the filename
gamefile.rename(
Path(gamefile.parent, f"{gamefile.stem}_{date}" + gamefile.suffix))
elif(answer == "N"):
# Remove the old file
gamefile.unlink()
except OSError as e:
print(e)
gamecounter = 0
try:
with open(gamefile, "a") as output:
for file in sorted(os.listdir(rompath)):
if file.endswith(".zip"):
print(os.path.join(file))
gamecounter += 1
output.write(file+"\n")
print(f"There's {gamecounter} games in the list.")
except OSError as e:
print(e)
if __name__ == '__main__':
main()