diff --git a/GlobalConf.toml b/GlobalConf.toml index 0646441..925d069 100644 --- a/GlobalConf.toml +++ b/GlobalConf.toml @@ -1,5 +1,5 @@ Title = "SaraSortd Config" -Version = "7.4" +Version = "7.5" SafeMode = 1 SilentMode = 0 SortTimer = 1 diff --git a/InputDirConf.toml b/InputDirConf.toml index f29347e..6652ba0 100644 --- a/InputDirConf.toml +++ b/InputDirConf.toml @@ -1,5 +1,5 @@ Title = "Unset" -Version = "7.4" +Version = "7.5" ParentDir = "Unset" SortDirs = 0 diff --git a/OutputDirConf.toml b/OutputDirConf.toml index a32d84a..9c1692a 100644 --- a/OutputDirConf.toml +++ b/OutputDirConf.toml @@ -1,5 +1,5 @@ Title = "Unset" -Version = "7.4" +Version = "7.5" LastFile = "Unset" ParentDir = "Unset" ValidInputDirs = ["*"] diff --git a/README.md b/README.md index 6856564..758253b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ SaraSortd: a file and directory sorting daemon built with python. -(Version = "7.4") +(Version = "7.5") It's made by Sarah, hence the name. :3 @@ -58,7 +58,7 @@ Here's a step-by-step tutorial (in case you don't want to watch the video). ``` Title = "SaraSortd Config" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "7.4" # Just the version number for the config file. +Version = "7.5" # 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. @@ -170,7 +170,7 @@ The output directory config references the SaraSortd config (GlobalConf.toml). T ``` Title = "Unset" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "7.4" # The version number of the config. +Version = "7.5" # 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. @@ -226,7 +226,7 @@ Overwrite = 1 # Whether this specific file type can be overwritten by others of ``` Title = "Unset" # NOTE: Do not change the title. This is so that the program knows which config file is which. -Version = "7.4" +Version = "7.5" ParentDir = "Unset" # The name of this directory. It gets automatically updated when this config gets copied to an output directory. diff --git a/SaraSortd.py b/SaraSortd.py index 9a77abe..81a1429 100644 --- a/SaraSortd.py +++ b/SaraSortd.py @@ -6,7 +6,7 @@ import shutil import time import toml -# Version = "7.4" +# Version = "7.5" ConfPath = "./GlobalConf.toml" @@ -235,16 +235,21 @@ def ConfFolder(PathText): return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(ConfPath)), PathText)) +def Slashes(Path): + # Windows paths use "\\" (and configs may mix both); compare and name them with "/" only. + return Path.replace("\\", "/") + + def FlatName(Path): # A directory's name for files kept outside it: its path below RootDir (or its whole path), "/" turned into "_". - # E.G: "%RootDir%/Pictures/Cats" becomes "Pictures_Cats". - Root = ParsePath(ConfDirs.get("RootDir", "")).rstrip("/") - Path = Path.rstrip("/") + # E.G: "%RootDir%/Pictures/Cats" becomes "Pictures_Cats". On Windows a drive's ":" is dropped (not allowed in names). + Root = Slashes(ParsePath(ConfDirs.get("RootDir", ""))).rstrip("/") + Path = Slashes(Path).rstrip("/") if Root and Path.startswith(Root + "/"): Relative = Path[len(Root) + 1:] else: Relative = Path.strip("/") or os.path.basename(Path) - return Relative.replace("/", "_") + return Relative.replace(":", "").replace("/", "_") def CentralConf(Path, Kind): @@ -252,7 +257,7 @@ def CentralConf(Path, Kind): # [DirConfs] names a file per directory ("dir" = "file", or "dir" = { In = "file", Out = "file" }), # and DirConfDir holds the configs of every directory [DirConfs] doesn't name. None means inside the directory. for Key, Value in (Conf.get("DirConfs") or {}).items(): - if ParsePath(Key).rstrip("/") == Path.rstrip("/"): + if Slashes(ParsePath(Key)).rstrip("/") == Slashes(Path).rstrip("/"): if isinstance(Value, dict): Value = Value.get(Kind) if Value: @@ -301,7 +306,7 @@ def Clone(Source, Destination, NewName, Delete = False): with open(FileHistoryPath, "w", encoding = "utf-8") as HistoryFile: toml.dump(HistoryFileData, HistoryFile) - os.rename(Source, os.path.join(Destination, NewName)) + os.replace(Source, os.path.join(Destination, NewName)) # overwrites on Windows too, like rename on Linux return Dir(Destination, Output = False, CopyConf = False) diff --git a/__pycache__/SaraSortd.cpython-314.pyc b/__pycache__/SaraSortd.cpython-314.pyc new file mode 100644 index 0000000..4cc8b9b Binary files /dev/null and b/__pycache__/SaraSortd.cpython-314.pyc differ