From 05c5a7b1c17df674276566025af3663a9ad7a43b Mon Sep 17 00:00:00 2001 From: Sarahtonin Date: Fri, 10 Apr 2026 18:30:49 +0200 Subject: [PATCH] Added an overwrite parameter to [[Files]], to allow or deny overwriting of specific files. --- Config.toml | 4 ++-- DirConfig.toml | 1 + SaraSortd.py | 36 ++++++++++++++++++++---------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Config.toml b/Config.toml index 4018427..eabb173 100644 --- a/Config.toml +++ b/Config.toml @@ -22,8 +22,8 @@ VarCall = "%%" [DirectoryPaths] RootDir = "Unset" -InputDir = [ "%RootDir%/Input"] -OutputDir = [ "%RootDir%/Output"] +InputDir = [ "%RootDir%/Input" ] +OutputDir = [ "%RootDir%/Output" ] LogDir = "%RootDir%/.Logs" FailedDir = "%RootDir%/.Failed" diff --git a/DirConfig.toml b/DirConfig.toml index f3cd857..99f515d 100644 --- a/DirConfig.toml +++ b/DirConfig.toml @@ -9,3 +9,4 @@ NewFileName = "~^" NextNum = 1 NextChar = "A" CaseSensitive = 0 +Overwrite = 1 diff --git a/SaraSortd.py b/SaraSortd.py index 4f6a6df..9794ab9 100644 --- a/SaraSortd.py +++ b/SaraSortd.py @@ -214,7 +214,7 @@ def Dir(Path, Output = True, CopyConf = True): ParentName, ) UpdateConf( - f"{Path}/{Parse(String=ConfNames['DirConfName'], Path=ConfPath, Parent=ParentName)}.toml", + f"{Path}/{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml", "Title", f"{ParentName} Config", ) @@ -233,12 +233,8 @@ def LogWrite(Text): ConfNames["LogFileName"] is not None and ConfNames["LogFileName"] != "Unset" ): - Dir( - Parse(String=ConfDirs["LogDir"], Path=ConfPath), - Output=False, - CopyConf=False, - ) - LogFile = f"{Parse(String=ConfDirs['LogDir'], Path=ConfPath)}/{Parse(String=ConfNames['LogFileName'], Path=ConfPath)}.log" + Dir(Parse(String = ConfDirs["LogDir"], Path = ConfPath), Output = False, CopyConf = False) + LogFile = f"{Parse(String = ConfDirs['LogDir'], Path = ConfPath)}/{Parse(String = ConfNames['LogFileName'], Path = ConfPath)}.log" with open(LogFile, "a", encoding = "utf-8", buffering = 1) as File: File.write(f"{Parse(String = ConfLog['All'], Path = ConfPath)}{Text}\n") @@ -292,6 +288,18 @@ def DecideNewPath(FilePath): if Match: NewFileName = File["NewFileName"] + NewFileName = Parse( + String = NewFileName, + Path = DirConfPath, + OrgFile = UnsortedFile, + NextNum = File["NextNum"], + NextChar = File["NextChar"], + Parent = ParentName, + ) + + if File["Overwrite"] == 0 and os.path.exists(os.path.join(Output, NewFileName)): + continue + if ConfVars["NextNum"] in NewFileName: UpdateConf( DirConfPath, @@ -305,14 +313,6 @@ def DecideNewPath(FilePath): NewChar = chr(((ord(CurrentChar.upper()) - 65 + 1) % 26) + 65) UpdateConf(DirConfPath, "NextChar", NewChar) - NewFileName = Parse( - String = NewFileName, - Path = DirConfPath, - OrgFile = UnsortedFile, - NextNum = File["NextNum"], - NextChar = File["NextChar"], - Parent = ParentName, - ) return f"{Output}/{NewFileName}" @@ -365,6 +365,10 @@ def Init(): CheckConf() if Start: + for InputDir in ConfDirs["InputDir"]: + InputDir = Parse(String = InputDir, Path = ConfPath, Parent = os.path.basename(os.path.dirname(InputDir))) + Dir(InputDir, Output = False, CopyConf = False) + TextOutput = Parse(String = ConfLog["Start"], Path = ConfPath) LogWrite(TextOutput) Speak(TextOutput) @@ -384,7 +388,7 @@ def Init(): def Main(): for Output in ConfDirs["OutputDir"]: - Output = Parse(String = Output) + Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(Output))) Dir(Output) try: