11 Commits
Author SHA1 Message Date
sarah 68e33861a9 Merge pull request #49 from SRHTNIN/SarahTest
SarahTest=>Main
2026-04-29 07:52:33 +02:00
sarah f0b2ec62ef Added function to InputDirConf, including pattern and if the input
should sort directories or not. Also added zipping functions to move
said directories. TODO: Add unzipping functions.
2026-04-29 07:50:04 +02:00
sarah 37af52eaa0 Merge pull request #48 from SRHTNIN/SarahTest
Sarah test
2026-04-28 18:53:47 +02:00
sarah 2afadaebc8 Fixed NextNum and NextChar bug. Also changed all mentions of Version to
be (Version = "5.1") for easier replacement for new updates.
2026-04-28 15:36:44 +02:00
sarah 84d61d9381 Update README.md 2026-04-21 11:20:08 +02:00
sarah 0f2f6673aa Renamed files. 2026-04-21 11:12:44 +02:00
sarah f2bc2abf9c Merge pull request #45 from SRHTNIN/SarahTest
Sarah test
2026-04-20 20:09:53 +02:00
sarah 5933dd94d2 Merge branch 'SarahTest' of https://github.com/SRHTNIN/Sarasort into SarahTest 2026-04-20 20:09:20 +02:00
sarah 24c52c17ce Added versioning in files, and fixed config files to be unset. 2026-04-20 20:09:07 +02:00
sarah fd4f7256df Merge pull request #44 from SRHTNIN/main
I want the readme.
2026-04-20 20:04:53 +02:00
sarah d43085de71 Update README.md 2026-04-20 20:04:20 +02:00
5 changed files with 162 additions and 66 deletions

No files matched your search

+48 -19
View File
@@ -1,16 +1,10 @@
# SaraSortd # SaraSortd
(Version = "6.0")
A python daemon that can automatically sort your files to your liking without using AI. A python daemon that can automatically sort your files to your liking without using AI.
It's made by Sarah, hence the name. :3 It's made by Sarah, hence the name. :3
The versioning for SaraSortd is like so: the first number going up means that your
previous config files won't work anymore with the new SaraSortd.py.
The second number going up means that something has been changed, but you can still
use your old config files with SaraSortd.py.
## Usage ## Usage
SaraSortd is for people who don't want to manually sort files, people who want to organise files, and people who want an automatic naming standard for their files. SaraSortd is for people who don't want to manually sort files, people who want to organise files, and people who want an automatic naming standard for their files.
@@ -23,17 +17,21 @@ Example use-cases:
- Regularly cloning important files into a backup directory. - Regularly cloning important files into a backup directory.
## Dependencies ## Dependencies
python python
toml: Use ```pip install toml``` to install toml. toml: Use ```pip install toml``` to install toml.
## Versioning
If the first number in the version goes up, it means that old config files will not work with the new SaraSortd.py.
If the second number in the version goes up, something new got added, but your old config files will still work just fine.
## Installation ## Installation
Here's an [installation video.](https://youtu.be/ZMIaOhZA0kE). Here's an [installation video](https://youtu.be/ZMIaOhZA0kE).
Here's a step-by-step tutorial (in case you don't want to watch the video). Here's a step-by-step tutorial (in case you don't want to watch the video).
1. Install ZIP-file. 1. Install ZIP-file.
@@ -45,10 +43,12 @@ Here's a step-by-step tutorial (in case you don't want to watch the video).
## Config explanation ## Config explanation
### SaraSortd Config (Config.toml) ### SaraSortd Config (GlobalConf.toml)
``` ```
Title = "SaraSortd Config" # NOTE: Do not change the title. Title = "SaraSortd Config" # NOTE: Do not change the title. This is so that the program knows which config file is which.
Version = "6.0" # Just the version number for the config file.
SafeMode = 1 # If SaraSortd should stop if an error with the config appears. 1 is stop, 0 is continue. SafeMode = 1 # If SaraSortd should stop if an error with the config appears. 1 is stop, 0 is continue.
@@ -60,10 +60,10 @@ DotFiles = 0 # If SaraSortd should sort files that begin with ".". This is mainl
Logging = 1 # If SaraSortd's logging system should be active. If this is 0, nothing will be logged into files. Logging = 1 # If SaraSortd's logging system should be active. If this is 0, nothing will be logged into files.
OverwriteDirConf = 0 # If SaraSortd should overwrite directory configs with DirConfig.toml. 0 is no, 1 is yes. OverwriteDirConf = 0 # If SaraSortd should overwrite directory configs with the config templates. 0 is no, 1 is yes.
[Variables] # Only use these in config files, not the actual file names themselves. [Variables] # Only use these in config files, not the actual file names themselves.
NextNum = "*" # The next available number. If 1 already exists, 2 will be used. Starts at 1. NextNum = "*" # The next available number. If 1 already exists, 2 will be used.
NextChar = "&" # The next available character. If A already exists, B will be used. NextChar = "&" # The next available character. If A already exists, B will be used.
@@ -128,19 +128,30 @@ ValueSet = "Set: %%." # When a value in a config is set.
Unset = "Error: %% is not set." # When a value isn't set. Unset = "Error: %% is not set." # When a value isn't set.
# %% here is just the parameter who's value was either "Unset" or None. E.G: "RootDir". # %% here is just the parameter who's value was either "Unset" or None. E.G: "RootDir".
Zipping = "Zipping: %%." # When a directory is zipped.
# %% here is the path to the directory being zipped.
Unzipping = "Unzipping: %%." # When a directory gets unzipped.
# %% is the path to the directory being unzipped.
NoPermission = "Error: No permission to %%." # When SaraSortd lacks permission to do something.
# %% is the action that the program had no permission to do. E.G. "remove directory /home/bob/exampledir".
``` ```
### Output Directory Config (DirConfig.toml) ### Output Directory Config (OutputDirConf.toml)
The output directory config references the SaraSortd config (Config.toml). This means that you can, for example, use the character assigned to "NextNum" in Config.toml in this config (DirConfig.toml). This applies to all Variables in the SaraSortd config (Config.toml). The output directory config references the SaraSortd config (GlobalConf.toml). This means that you can, for example, use the character assigned to "NextNum" in GlobalConf.toml in this config (OutputDirConf.toml). This applies to all Variables in the SaraSortd config (GlobalConf.toml).
``` ```
Title = "Unset" # The title of the config. This currently does nothing for SaraSortd, so it can be anything. It gets automatically updated when DirConfig.toml gets copied to an output directory. Title = "Unset" # NOTE: Do not change the title. This is so that the program knows which config file is which.
Version = "6.0" # The version number of the config.
LastFile = "Unset" # The last file that was sorted to this directory. It gets automatically updated whenever a file gets sorted to this directory. LastFile = "Unset" # The last file that was sorted to this directory. It gets automatically updated whenever a file gets sorted to this directory.
ParentDir = "Unset" # The name of this directory. It gets automatically updated when DirConfig.toml gets copied to an output directory. ParentDir = "Unset" # The name of this directory. It gets automatically updated when this config gets copied to an output directory.
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. 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.
@@ -170,11 +181,29 @@ Pattern = "*" # A pattern used to sort files to this directory. * is a wildcard;
NewFileName = "~^" # A pattern for the new names of the files that get sorted to this directory from matching this "Pattern". NewFileName = "~^" # A pattern for the new names of the files that get sorted to this directory from matching this "Pattern".
NextNum = 1 # Used to keep track of the next available number for file names. If you have two of the character that represents NextNum (Found in Config.toml), you can stack them together to make 01 or 001 instead of 1. It gets automatically incremented when NextNum is used in NewFileName, and a file gets sorted to this directory and renamed. NextNum = 1 # Used to keep track of the next available number for file names. If you change NextNum to be 01 or 001 instead of 1, it'll still work. 09 => 10. It gets automatically incremented when NextNum is used in NewFileName, and a file gets sorted to this directory and renamed.
NextChar = "A" # Used to keep track of the next available letter for file names. It gets automatically incremented (E.G: A into B or AA into AB then AZ into BA) when NextChar is used in NewFileName, and a file gets sorted to this directory and renamed. NextChar = "A" # Used to keep track of the next available letter for file names. If you change NextChar to be AA or AAA instead of A, it'll still work. AZ => BA. It gets automatically incremented (E.G: A into B or AA into AB then AZ into BA) when NextChar is used in NewFileName, and a file gets sorted to this directory and renamed.
CaseSensitive = 0 # Whether this "Pattern" is case-sensitive or not. 1 is yes, 0 is no. E.G: if CaseSensitive = 1 and this "Pattern" is "*.PNG", a file named "picture.png" won't get sorted to this directory. If CaseSensitive = 0 and this "Pattern" is "*.PNG", a file named "picture.png" *will* get sorted to this directory. CaseSensitive = 0 # Whether this "Pattern" is case-sensitive or not. 1 is yes, 0 is no. E.G: if CaseSensitive = 1 and this "Pattern" is "*.PNG", a file named "picture.png" won't get sorted to this directory. If CaseSensitive = 0 and this "Pattern" is "*.PNG", a file named "picture.png" *will* get sorted to this directory.
Overwrite = 1 # Whether this specific file type can be overwritten by others of the same type. 0 is no, 1 is yes. Overwrite = 1 # Whether this specific file type can be overwritten by others of the same type. 0 is no, 1 is yes.
``` ```
### Input Directory Config (InputDirConf.toml)
```
Title = "Unset" # NOTE: Do not change the title. This is so that the program knows which config file is which.
Version = "6.0"
ParentDir = "Unset" # The name of this directory. It gets automatically updated when this config gets copied to an output directory.
SortDirs = 0
[[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.
Pattern = "*" # A pattern used to decide if a file should be sorted or not. * is a wildcard; ? is a one-character wildcard. E.G: if Pattern is "*.png", all files ending with .png in this directory will try to be sorted.
CaseSensitive = 0 # Whether Pattern is case-sensitive or not. If CaseSensitive = 1 and your pattern is "*.PNG", then a file named "example.png" won't be sorted.
```
+7 -2
View File
@@ -1,4 +1,5 @@
Title = "SaraSortd Config" Title = "SaraSortd Config"
Version = "6.0"
SafeMode = 1 SafeMode = 1
SilentMode = 0 SilentMode = 0
CheckInput = 5 CheckInput = 5
@@ -21,7 +22,7 @@ Second = "[s]"
VarCall = "%%" VarCall = "%%"
[DirectoryPaths] [DirectoryPaths]
RootDir = "/home/sarah/TestDir" RootDir = "C:/Users/StigOscarAadalen-Aas/OneDrive - Telemark fylkeskommune/Desktop/Testdir"
InputDir = [ "%RootDir%/Input" ] InputDir = [ "%RootDir%/Input" ]
OutputDir = [ "%RootDir%/Output" ] OutputDir = [ "%RootDir%/Output" ]
LogDir = "%RootDir%/.Logs" LogDir = "%RootDir%/.Logs"
@@ -29,7 +30,8 @@ FailedDir = "%RootDir%/.Failed"
[Names] [Names]
LogFileName = "[y].[m].[d]" LogFileName = "[y].[m].[d]"
DirConfName = ".@Config" InDirConfName = ".@Config"
OutDirConfName = ".@Config"
FileHistoryName = ".@History" FileHistoryName = ".@History"
[Log] [Log]
@@ -42,3 +44,6 @@ Sorted = "Sorted %%."
NotSorted = "Error: Failed to sort %%. No valid output directory." NotSorted = "Error: Failed to sort %%. No valid output directory."
ValueSet = "Set %%." ValueSet = "Set %%."
Unset = "Error: %% is not set." Unset = "Error: %% is not set."
Zipping = "Zipping: %%."
Unzipping = "Unzipping: %%."
NoPermission = "Error: No permission to %%."
+8
View File
@@ -0,0 +1,8 @@
Title = "Unset"
Version = "6.0"
ParentDir = "Unset"
SortDirs = 0
[[Files]]
Pattern = "*"
CaseSensitive = 0
+2 -1
View File
@@ -1,4 +1,5 @@
Title = "Unset" Title = "Unset"
Version = "6.0"
LastFile = "Unset" LastFile = "Unset"
ParentDir = "Unset" ParentDir = "Unset"
ValidInputDirs = ["*"] ValidInputDirs = ["*"]
@@ -8,7 +9,7 @@ DeleteOrg = 1
[[Files]] [[Files]]
Pattern = "*" Pattern = "*"
NewFileName = "~^" NewFileName = "~^"
NextNum = 1 NextNum = "1"
NextChar = "A" NextChar = "A"
CaseSensitive = 0 CaseSensitive = 0
Overwrite = 1 Overwrite = 1
+97 -44
View File
@@ -6,7 +6,9 @@ import shutil
import time import time
import toml import toml
ConfPath = "./Config.toml" # Version = "6.0"
ConfPath = "./GlobalConf.toml"
Conf = None Conf = None
ConfVars = None ConfVars = None
@@ -215,26 +217,44 @@ def Clone(Source, Destination, NewName, Delete = False):
os.remove(Source) os.remove(Source)
def Dir(Path, Output = True, CopyConf = True): def Dir(Path, Output = True, CopyConf = "OutputDirConf.toml"):
ParentName = os.path.basename(Path) ParentName = os.path.basename(Path)
os.makedirs(Path, exist_ok=True) os.makedirs(Path, exist_ok=True)
if CopyConf: if CopyConf:
NewDirConf = f"{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml" if "Out" in CopyConf:
if Conf["OverwriteDirConf"] == 1 or not os.path.exists( NewDirConf = f"{Parse(String = ConfNames['OutDirConfName'], Path = ConfPath, Parent = ParentName)}.toml"
os.path.join(f"{Path}/{NewDirConf}")
): if Conf["OverwriteDirConf"] == 1 or not os.path.exists(os.path.join(f"{Path}/{NewDirConf}")):
Clone("DirConfig.toml", Path, NewDirConf) Clone(CopyConf, Path, NewDirConf)
UpdateConf( UpdateConf(
f"{Path}/{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml", f"{Path}/{Parse(String = ConfNames['OutDirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
"ParentDir", "ParentDir",
ParentName, ParentName,
) )
UpdateConf(
f"{Path}/{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml", UpdateConf(
"Title", f"{Path}/{Parse(String = ConfNames['OutDirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
f"{ParentName} Config", "Title",
) f"{ParentName} Config",
)
if "In" in CopyConf:
NewDirConf = f"{Parse(String = ConfNames['InDirConfName'], Path = ConfPath, Parent = ParentName)}.toml"
if Conf["OverwriteDirConf"] == 1 or not os.path.exists(os.path.join(f"{Path}/{NewDirConf}")):
Clone(CopyConf, Path, NewDirConf)
UpdateConf(
f"{Path}/{Parse(String = ConfNames['InDirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
"ParentDir",
ParentName,
)
UpdateConf(
f"{Path}/{Parse(String = ConfNames['InDirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
"Title",
f"{ParentName} Config",
)
if Output: if Output:
ParsedPath = Parse(String = Path) ParsedPath = Parse(String = Path)
@@ -264,13 +284,13 @@ def DecideNewPath(FilePath):
ParentName = os.path.basename(Output) ParentName = os.path.basename(Output)
DirConfName = Parse(String = ConfNames["DirConfName"], Path = ConfPath, Parent = ParentName) OutDirConfName = Parse(String = ConfNames["OutDirConfName"], Path = ConfPath, Parent = ParentName)
DirConfPath = f"{Output}/{DirConfName}.toml" OutDirConfPath = f"{Output}/{OutDirConfName}.toml"
ValidInputDirs = GetConf("ValidInputDirs", DirConfPath) ValidInputDirs = GetConf("ValidInputDirs", OutDirConfPath)
for ValidInputDir in ValidInputDirs: for ValidInputDir in ValidInputDirs:
ValidInputDir = Parse(String = ValidInputDir, Parent = GetConf("ParentDir", DirConfPath)) ValidInputDir = Parse(String = ValidInputDir, Parent = GetConf("ParentDir", OutDirConfPath))
TextOutput = Parse(String = ConfLog["MatchPattern"], VarCall = f"{os.path.dirname(FilePath)} against {ValidInputDir}") TextOutput = Parse(String = ConfLog["MatchPattern"], VarCall = f"{os.path.dirname(FilePath)} against {ValidInputDir}")
LogWrite(TextOutput) LogWrite(TextOutput)
@@ -280,12 +300,12 @@ def DecideNewPath(FilePath):
if (InputDirValid): if (InputDirValid):
break break
if not os.path.exists(DirConfPath) or not InputDirValid: if not os.path.exists(OutDirConfPath) or not InputDirValid:
continue continue
OutputFiles = 0 OutputFiles = 0
FileLimitConf = GetConf("FileLimit", DirConfPath) FileLimitConf = GetConf("FileLimit", OutDirConfPath)
if FileLimitConf > 0: if FileLimitConf > 0:
for OutputFile in os.listdir(Output): for OutputFile in os.listdir(Output):
@@ -297,7 +317,7 @@ def DecideNewPath(FilePath):
if OutputFiles >= FileLimitConf: if OutputFiles >= FileLimitConf:
continue continue
FileConf = GetConf("Files", DirConfPath) FileConf = GetConf("Files", OutDirConfPath)
if not FileConf: if not FileConf:
continue continue
@@ -318,25 +338,26 @@ def DecideNewPath(FilePath):
if Match: if Match:
NewFileName = File["NewFileName"] NewFileName = File["NewFileName"]
NewFileName = Parse(String = NewFileName, Path = DirConfPath, OrgFile = UnsortedFile, NextNum = File["NextNum"], NextChar = File["NextChar"], Parent = ParentName) NewFileName = Parse(String = NewFileName, Path = OutDirConfPath, OrgFile = UnsortedFile, NextNum = File["NextNum"], NextChar = File["NextChar"], Parent = ParentName)
if File["Overwrite"] == 0 and os.path.exists(os.path.join(Output, NewFileName)): if File["Overwrite"] == 0 and os.path.exists(os.path.join(Output, NewFileName)):
continue continue
if ConfVars["NextNum"] in File["NewFileName"]: if ConfVars["NextNum"] in File["NewFileName"]:
ConfData = toml.load(DirConfPath) ConfData = toml.load(OutDirConfPath)
Width = len(File["NextNum"])
NewNum = (int(File["NextNum"]) + 1) NewNum = str((int(File["NextNum"]) + 1)).rjust(Width, "0")
print(File["NextNum"],"=>",NewNum)
for Item in ConfData.get("Files", []): for Item in ConfData.get("Files", []):
if Item.get("Pattern") == File["Pattern"]: if Item.get("Pattern") == File["Pattern"]:
Item["NextNum"] = NewNum Item["NextNum"] = NewNum
break break
with open(DirConfPath, "w", encoding="utf-8") as ConfFile: with open(OutDirConfPath, "w", encoding="utf-8") as ConfFile:
toml.dump(ConfData, ConfFile) toml.dump(ConfData, ConfFile)
TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewNum}") TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextNum to {NewNum}")
LogWrite(TextOutput) LogWrite(TextOutput)
Speak(TextOutput) Speak(TextOutput)
@@ -361,14 +382,14 @@ def DecideNewPath(FilePath):
NewChar = "".join(Result) NewChar = "".join(Result)
ConfData = toml.load(DirConfPath) ConfData = toml.load(OutDirConfPath)
for Item in ConfData.get("Files", []): for Item in ConfData.get("Files", []):
if Item.get("Pattern") == File["Pattern"]: if Item.get("Pattern") == File["Pattern"]:
Item["NextChar"] = NewChar Item["NextChar"] = NewChar
break break
with open(DirConfPath, "w", encoding="utf-8") as ConfFile: with open(OutDirConfPath, "w", encoding="utf-8") as ConfFile:
toml.dump(ConfData, ConfFile) toml.dump(ConfData, ConfFile)
TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewChar}") TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewChar}")
@@ -394,7 +415,7 @@ def Sort(FilePath):
NewDirPath = os.path.dirname(NewPath) NewDirPath = os.path.dirname(NewPath)
NewName = os.path.basename(NewPath) NewName = os.path.basename(NewPath)
if (GetConf("DeleteOrg", f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = (os.path.basename(NewDirPath)))}.toml") == 1): if (GetConf("DeleteOrg", f"{NewDirPath}/{Parse(String = ConfNames['OutDirConfName'], Parent = (os.path.basename(NewDirPath)))}.toml") == 1):
Delete = True Delete = True
else: else:
@@ -402,7 +423,7 @@ def Sort(FilePath):
try: try:
Clone(FilePath, NewDirPath, NewName, Delete) Clone(FilePath, NewDirPath, NewName, Delete)
UpdateConf(f"{NewDirPath}/{Parse(String = ConfNames['DirConfName'], Parent = os.path.basename(NewDirPath))}.toml", "LastFile", NewName) UpdateConf(f"{NewDirPath}/{Parse(String = ConfNames['OutDirConfName'], 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) LogWrite(TextOutput)
@@ -429,14 +450,14 @@ def Init():
if Start: if Start:
for InputDir in ConfDirs["InputDir"]: for InputDir in ConfDirs["InputDir"]:
InputDir = Parse(String = InputDir, Path = ConfPath, Parent = os.path.basename(os.path.dirname(InputDir))) InputDir = Parse(String = InputDir, Path = ConfPath, Parent = os.path.basename(os.path.dirname(InputDir)))
Dir(InputDir, Output = False, CopyConf = False) Dir(InputDir, Output = False, CopyConf = "InputDirConf.toml")
for Output in ConfDirs["OutputDir"]: for Output in ConfDirs["OutputDir"]:
Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(Output))) Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(Output)))
Dir(Output) Dir(Output)
DirConfPath = f"{Output}/{Parse(String = ConfNames["DirConfName"], Parent = os.path.basename(Output))}.toml" OutDirConfPath = f"{Output}/{Parse(String = ConfNames["OutDirConfName"], Parent = os.path.basename(Output))}.toml"
ConfData = toml.load(DirConfPath) ConfData = toml.load(OutDirConfPath)
for Item in ConfData.get("Files", []): for Item in ConfData.get("Files", []):
Character = re.escape(ConfVars["NextChar"]) Character = re.escape(ConfVars["NextChar"])
@@ -446,7 +467,7 @@ def Init():
if Width > 0: if Width > 0:
Item["NextChar"] = Item["NextChar"].upper().rjust(Width, "A") Item["NextChar"] = Item["NextChar"].upper().rjust(Width, "A")
with open(DirConfPath, "w", encoding = "utf-8") as ConfFile: with open(OutDirConfPath, "w", encoding = "utf-8") as ConfFile:
toml.dump(ConfData, ConfFile) toml.dump(ConfData, ConfFile)
TextOutput = Parse(String = ConfLog["Start"], Path = ConfPath) TextOutput = Parse(String = ConfLog["Start"], Path = ConfPath)
@@ -460,7 +481,7 @@ def Init():
Speak(TextOutput) Speak(TextOutput)
else: 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 'GlobalConf.toml' is in the same directory as 'SaraSortd.py'")
def Main(): def Main():
@@ -474,6 +495,9 @@ def Main():
if not os.path.exists(InputPath): if not os.path.exists(InputPath):
continue continue
InputDirConfPath = f"{InputPath}/{Parse(ConfNames["InDirConfName"], Parent = os.path.basename(InputPath))}.toml"
InputDirConf = toml.load(InputDirConfPath)
for Output in ConfDirs["OutputDir"]: for Output in ConfDirs["OutputDir"]:
OutputPath = Parse(Output) OutputPath = Parse(Output)
@@ -487,11 +511,41 @@ def Main():
for FileName in os.listdir(InputPath): for FileName in os.listdir(InputPath):
FilePath = f"{InputPath}/{FileName}" FilePath = f"{InputPath}/{FileName}"
if os.path.isdir(FilePath) and InputDirConf["SortDirs"] == 0:
continue
if os.path.isfile(FilePath): FileName = os.path.basename(FilePath)
FileName = os.path.basename(FilePath) if FileName.startswith(".") and Conf["DotFiles"] == 0:
if FileName.startswith(".") and Conf["DotFiles"] == 0: continue
continue
for ConfFile in InputDirConf["Files"]:
if ConfFile["CaseSensitive"] == 1:
Match = fnmatch.fnmatchcase(FileName, Parse(ConfFile["Pattern"], Parent = os.path.basename(InputPath)))
else:
Match = fnmatch.fnmatchcase(FileName.lower(), (Parse(ConfFile["Pattern"], Parent = os.path.basename(InputPath))).lower())
if Match:
break
if Match:
if os.path.isdir(FilePath) and InputDirConf["SortDirs"] == 1:
TextOutput = Parse(String = ConfLog["Zipping"], VarCall = FilePath)
LogWrite(TextOutput)
Speak(TextOutput)
shutil.make_archive(FilePath, "zip", FilePath)
try:
os.rmdir(FilePath)
except PermissionError:
TextOutput = Parse(String = ConfLog["NoPermission"], VarCall = f"remove directory {InputPath}/{FileName}")
LogWrite(TextOutput)
Speak(TextOutput)
continue
FilePath = f"{FilePath}.zip"
if RecurseDir: if RecurseDir:
HistoryFile = toml.load(FileHistoryPath) HistoryFile = toml.load(FileHistoryPath)
@@ -508,5 +562,4 @@ def Main():
LogWrite(TextOutput) LogWrite(TextOutput)
Speak(TextOutput) Speak(TextOutput)
Init() Init()