From d68550d0a9b51f26e9f1fbf8ce08f2a5a4c3fe9b Mon Sep 17 00:00:00 2001 From: Sarahtonin Date: Tue, 14 Apr 2026 07:20:38 +0200 Subject: [PATCH] Added delete parameter to dirconf. --- .Github/README.md | 4 +++- Config.toml | 2 +- DirConfig.toml | 1 + SaraSortd.py | 37 +++++++++++++++++-------------------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.Github/README.md b/.Github/README.md index d5fa372..593543f 100644 --- a/.Github/README.md +++ b/.Github/README.md @@ -142,7 +142,9 @@ ParentDir = "Unset" # The name of this directory. It gets automatically updated ValidInputDirs = ["*"] # Directories that are valid for sorting. Basically, if a file is from one of these directories, they can be sorted here. * is a wildcard; ? is a one-character wilcard. E.G: if "ValidInputDirs = ["/TestDir/*"]" any file from any directory in "/TestDir" will be allowed to be sorted here. -FileLimit = 0 +FileLimit = 0 # The max limit of files a directory can have. If this is 0, then there's no limit. + +DeleteOrg = 1 # If SaraSortd should delete the original file or not. If this is 1, then sorted files will be 'moved' to an output directory. If not, they will be 'copied' to an output directory. [[Files]] # The double brackets means that you can add multiple types of files to be sorted here. Just copy [[Files]] and all the parameters under it, and paste it under or over this section, then you may change the values of the new parameters. E.G: diff --git a/Config.toml b/Config.toml index eabb173..71ee501 100644 --- a/Config.toml +++ b/Config.toml @@ -1,7 +1,7 @@ Title = "SaraSortd Config" SafeMode = 1 SilentMode = 0 -CheckInput = 3 +CheckInput = 10 DotFiles = 0 Logging = 1 OverwriteDirConf = 0 diff --git a/DirConfig.toml b/DirConfig.toml index 81accb5..c728179 100644 --- a/DirConfig.toml +++ b/DirConfig.toml @@ -3,6 +3,7 @@ LastFile = "Unset" ParentDir = "Unset" ValidInputDirs = ["*"] FileLimit = 0 +DeleteOrg = 1 [[Files]] Pattern = "*" diff --git a/SaraSortd.py b/SaraSortd.py index a24ee20..9435f49 100644 --- a/SaraSortd.py +++ b/SaraSortd.py @@ -266,7 +266,6 @@ def DecideNewPath(FilePath): if not os.path.exists(DirConfPath) or not InputDirValid: continue - OutputFiles = 0 FileLimitConf = GetConf("FileLimit", DirConfPath) @@ -365,37 +364,37 @@ def DecideNewPath(FilePath): def Sort(FilePath): NewPath = DecideNewPath(FilePath) + NewDirPath = os.path.dirname(NewPath) + NewName = os.path.basename(NewPath) + + if (GetConf("DeleteOrg", f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = (os.path.basename(NewDirPath)))}.toml") == 1): + Delete = True + + else: + Delete = False + if NewPath is None: Dir(Parse(String = ConfDirs["FailedDir"]), Output = False, CopyConf = False) NewName = os.path.basename(FilePath) - Clone(FilePath, Parse(String = ConfDirs["FailedDir"]), NewName, True) + Clone(FilePath, Parse(String = ConfDirs["FailedDir"]), NewName, Delete) TextOutput = Parse(String = ConfLog["NotSorted"], VarCall = FilePath) LogWrite(TextOutput) Speak(TextOutput) return - NewDirPath = os.path.dirname(NewPath) - NewName = os.path.basename(NewPath) - try: - Clone(FilePath, NewDirPath, NewName, True) - UpdateConf( - f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = os.path.basename(NewDirPath))}.toml", - "LastFile", - NewName, - ) + Clone(FilePath, NewDirPath, NewName, Delete) + UpdateConf(f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = os.path.basename(NewDirPath))}.toml", "LastFile", NewName) - TextOutput = Parse( - String = ConfLog["Sorted"], VarCall = f"{FilePath} to {NewDirPath}/{NewName}" - ) + TextOutput = Parse(String = ConfLog["Sorted"], VarCall = f"{FilePath} to {NewDirPath}/{NewName}") LogWrite(TextOutput) Speak(TextOutput) except Exception: Dir(Parse(String = ConfDirs["FailedDir"]), Output = False, CopyConf = False) NewName = os.path.basename(NewPath) - Clone(FilePath, Parse(String = ConfDirs["FailedDir"]), NewName, True) + Clone(FilePath, Parse(String = ConfDirs["FailedDir"]), NewName, Delete) TextOutput = Parse(String = ConfLog["NotSorted"], VarCall = FilePath) LogWrite(TextOutput) @@ -419,7 +418,7 @@ def Init(): Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(Output))) Dir(Output) - DirConfPath = f"{os.path.join(Output, Parse(String = ConfNames["DirConfName"], Parent = os.path.basename(Output)))}.toml" + DirConfPath = f"{Output}/{Parse(String = ConfNames["DirConfName"], Parent = os.path.basename(Output))}.toml" ConfData = toml.load(DirConfPath) for Item in ConfData.get("Files", []): @@ -444,9 +443,7 @@ def Init(): Speak(TextOutput) else: - print( - "NO CONFIG FOUND! Make sure the 'Config.toml' is in the same directory as 'SaraSortd.py'" - ) + print("NO CONFIG FOUND! Make sure the 'Config.toml' is in the same directory as 'SaraSortd.py'") def Main(): @@ -459,7 +456,7 @@ def Main(): continue for FileName in os.listdir(InputPath): - FilePath = os.path.join(InputPath, FileName) + FilePath = f"{InputPath}/{FileName}" if os.path.isfile(FilePath): FileName = os.path.basename(FilePath)