mirror of
https://git.srhtnin.garden/sarah/SaraSortd.git
synced 2026-10-13 18:38:11 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70a36d8b96 | ||
|
|
19ceec218f | ||
|
|
2cc72b1730 | ||
|
|
2bf4457981 | ||
|
|
5c39166a66 | ||
|
|
6a6e7dd494 | ||
|
|
a83b2e3c94 | ||
|
|
9be5938a87 | ||
|
|
4e00617e09 | ||
|
|
c5612654f8 | ||
|
|
324d06d6b4 | ||
|
|
b5afad3895 | ||
|
|
a314614055 | ||
|
|
3aa28f76cf | ||
|
|
89f4e59041 | ||
|
|
dc60a9828e | ||
|
|
4901d346f2 | ||
|
|
b04c3426a7 | ||
|
|
15ced89964 | ||
|
|
475eda8dd2 | ||
|
|
e9974f90ee | ||
|
|
68e33861a9 | ||
|
|
f0b2ec62ef | ||
|
|
37af52eaa0 | ||
|
|
2afadaebc8 | ||
|
|
84d61d9381 | ||
|
|
0f2f6673aa | ||
|
|
f2bc2abf9c | ||
|
|
5933dd94d2 | ||
|
|
24c52c17ce | ||
|
|
fd4f7256df | ||
|
|
d43085de71 | ||
|
|
dd00cf0780 | ||
|
|
51c557d228 | ||
|
|
e91ce510fc | ||
|
|
d68550d0a9 | ||
|
|
9fbdec9120 | ||
|
|
0b54a729ff | ||
|
|
a3bc726086 | ||
|
|
739f91a5bf | ||
|
|
fc6f9bd399 | ||
|
|
077cbbb2c1 | ||
|
|
ffd95fdfce | ||
|
|
49b5549b1d | ||
|
|
cbf1a4049c |
No files matched your search
@@ -1,138 +0,0 @@
|
||||
# SaraSortd
|
||||
A python daemon that can automatically sort your files to your liking without using AI.
|
||||
|
||||
It's made by Sarah, hence the name. :3
|
||||
|
||||
## Dependencies
|
||||
toml: Use ```pip install toml``` to install toml.
|
||||
|
||||
## Config explanation
|
||||
|
||||
### SaraSortd Config (Config.toml)
|
||||
|
||||
```
|
||||
Title = "SaraSortd Config" # NOTE: Do not change the title.
|
||||
|
||||
SafeMode = 1 # If SaraSortd should stop if an error with the config appears. 1 is stop, 0 is continue.
|
||||
|
||||
SilentMode = 0 # If SaraSortd should write things it does, to the terminal.
|
||||
|
||||
CheckInput = 3 # How many seconds it takes for SaraSortd to check input directories for new files to sort.
|
||||
|
||||
DotFiles = 0 # If SaraSortd should sort files that begin with ".". This is mainly for linux users, since hidden files always have "." in front of them.
|
||||
|
||||
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.
|
||||
|
||||
[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.
|
||||
|
||||
NextChar = "&" # The next available character. If A already exists, B will be used.
|
||||
|
||||
Parent = "@" # The name of the parent directory.
|
||||
|
||||
OrgFileName = "\~" # The original name of the sorted file. If "blahblah.txt" gets sorted, "~" would be equal to "blahblah".
|
||||
|
||||
OrgFileType = "^" # The original file type of the sorted file. If "example.png" gets sorted, "^" would be equal to ".png".
|
||||
|
||||
Year = "[y]" # The current year, E.G. "2026".
|
||||
|
||||
Month = "[m]" # The date of the current month, E.G. "03".
|
||||
|
||||
Day = "[d]" # The date of the current day, E.G. "27".
|
||||
|
||||
Hour = "[h]" # The current hour, E.G. "12".
|
||||
|
||||
Minute = "[n]" # The current minute, E.G. "44".
|
||||
|
||||
Second = "[s]" # The current second, E.G. "11".
|
||||
|
||||
VarCall = "%%" # The characters used at the start and end of variable calls. The first character is to the left; second is to the right. NOTE: If any parameters in the config uses just "%%", it gets a variable from the program itself, not from the config.
|
||||
|
||||
[DirectoryPaths]
|
||||
RootDir = "Unset" # A variable directory. This doesn't NEED to exist for the program to work. It's more of a shorthand for other paths to use! You could add more of these. E.G: Add ImageDir = "%RootDir%/Images", then you could set OutputDir to be "%ImageDir%".
|
||||
|
||||
InputDir = ["%RootDir%"] # If files get put here, they'll be sorted. This is a list, so you can add multiple. E.G: ["%RootDir%", "%RootDir%/input"]
|
||||
|
||||
OutputDir = ["%RootDir%/Output"] # Where sorted files go. This is a list, so you can add multiple. E.G: ["%RootDir%/Output", "%RootDir%/Output2"]. The output directories have separate config files.
|
||||
|
||||
LogDir = "%RootDir%/.Logs" # Where log files from SaraSortd go.
|
||||
|
||||
FailedDir ="%RootDir%/.Failed" # For files that failed to be sorted.
|
||||
|
||||
[Names]
|
||||
LogFileName = "[y].[m].[d]._*" # Name for log files.
|
||||
|
||||
DirConfName = ".@Config" # Name for config files for directories.
|
||||
|
||||
[Log]
|
||||
All = "[h]:[n]:[s] | " # What to put at the start of all lines in Log file.
|
||||
|
||||
Start = "Started: SaraSortd" # When SaraSortd starts.
|
||||
|
||||
NotStart = "Error: Failed to start SaraSortd." # When SaraSortd fails to start for some reason.
|
||||
|
||||
Stop = "\nStopped SaraSortd." # When SaraSortd stops for whatever reason. Usually when you interrupt it in the terminal you ran it in.
|
||||
|
||||
MatchPattern = "Checking %%." # When a file that's trying to be sorted gets checked against a pattern.
|
||||
# %% here is the file against the pattern. E.G: "picture.png against *.jpg"
|
||||
|
||||
Sorted = "Sorted: %%." # When a file gets sorted and where.
|
||||
# %% here is the oldfile to the newfile, E.G: "picture.png to SortedPicture.png".
|
||||
|
||||
NotSorted = "Error: Failed to sort %%. No valid output directory." # When a file from an input directory fails to be sorted to an output directory.
|
||||
# %% here is the path of the file. E.G: "/home/janedoe/picture.png".
|
||||
|
||||
ValueSet = "Set: %%." # When a value in a config is set.
|
||||
# %% here is the parameter and what it got set to. E.G: "Title to TestDir Config File".
|
||||
|
||||
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".
|
||||
```
|
||||
|
||||
### Output Directory Config (DirConfig.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).
|
||||
|
||||
```
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
[[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:
|
||||
|
||||
# [[Files]]
|
||||
# Pattern = "*.png"
|
||||
# NewFileName = "GoodImage^"
|
||||
# NextNum = 1
|
||||
# NextChar = "A"
|
||||
# CaseSensitive = 0
|
||||
# [[Files]]
|
||||
# Pattern = "*.jpg"
|
||||
# NewFileName = "BetterImage^"
|
||||
# NextNum = 1
|
||||
# NextChar = "A"
|
||||
# CaseSensitive = 0
|
||||
# Overwrite = 1
|
||||
|
||||
# Will sort .png files to this directory and rename them to "GoodImage.png", but also sort .jpg files into this directory yet rename those to "BetterImage.jpg".
|
||||
|
||||
Pattern = "*" # A pattern used to sort files to this directory. * is a wildcard; ? is a one-character wildcard. E.G: if Pattern is "*.png", all files ending with .png will end up here.
|
||||
|
||||
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. 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) 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.
|
||||
|
||||
Overwrite = 1 # Whether this specific file type can be overwritten by others of the same type. 0 is no, 1 is yes.
|
||||
```
|
||||
@@ -1,7 +1,8 @@
|
||||
Title = "SaraSortd Config"
|
||||
Version = "7.0"
|
||||
SafeMode = 1
|
||||
SilentMode = 0
|
||||
CheckInput = 3
|
||||
SortTimer = 1
|
||||
DotFiles = 0
|
||||
Logging = 1
|
||||
OverwriteDirConf = 0
|
||||
@@ -29,15 +30,20 @@ FailedDir = "%RootDir%/.Failed"
|
||||
|
||||
[Names]
|
||||
LogFileName = "[y].[m].[d]"
|
||||
DirConfName = ".@Config"
|
||||
InDirConfName = ".@Config"
|
||||
OutDirConfName = ".@Config"
|
||||
FileHistoryName = ".@History"
|
||||
|
||||
[Log]
|
||||
All = "[h]:[n]:[s] | "
|
||||
Start = "Started SaraSortd."
|
||||
NotStart = "Error: Failed to start SaraSortd."
|
||||
Stop = "\nStopped SaraSortd."
|
||||
Stop = "Stopped SaraSortd.\n"
|
||||
MatchPattern = "Checking %%."
|
||||
Sorted = "Sorted %%."
|
||||
NotSorted = "Error: Failed to sort %%. No valid output directory."
|
||||
ValueSet = "Set %%."
|
||||
Unset = "Error: %% is not set."
|
||||
Zipping = "Zipping: %%."
|
||||
Unzipping = "Unzipping: %%."
|
||||
NoPermission = "Error: No permission to %%."
|
||||
@@ -0,0 +1,8 @@
|
||||
Title = "Unset"
|
||||
Version = "7.0"
|
||||
ParentDir = "Unset"
|
||||
SortDirs = 0
|
||||
|
||||
[[Files]]
|
||||
Pattern = "*"
|
||||
CaseSensitive = 0
|
||||
File renamed without changes.
@@ -1,13 +1,16 @@
|
||||
Title = "Unset"
|
||||
Version = "7.0"
|
||||
LastFile = "Unset"
|
||||
ParentDir = "Unset"
|
||||
ValidInputDirs = ["*"]
|
||||
FileLimit = 0
|
||||
DeleteOrg = 1
|
||||
Unzip = []
|
||||
|
||||
[[Files]]
|
||||
Pattern = "*"
|
||||
NewFileName = "~^"
|
||||
NextNum = 1
|
||||
NextNum = "1"
|
||||
NextChar = "A"
|
||||
CaseSensitive = 0
|
||||
Overwrite = 1
|
||||
@@ -0,0 +1,228 @@
|
||||
<img align="center" src="https://github.com/SRHTNIN/RepoAssets/blob/main/SaraSortd/Banners/SaraSortd.png" width="100%" alt="SaraSortd: a file and directory sorting daemon built with python."/>
|
||||
|
||||
(Version = "7.0")
|
||||
|
||||
|
||||
It's made by Sarah, hence the name. :3
|
||||
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
<img align="center" src="https://github.com/SRHTNIN/RepoAssets/blob/main/SaraSortd/Banners/Usage.png" width="100%" alt="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.
|
||||
|
||||
Example use-cases:
|
||||
|
||||
- Sorting log files from multiple programs into one directory.
|
||||
|
||||
- Sorting downloaded github repositories to a directory for your IDE.
|
||||
|
||||
- Regularly cloning important files into a backup directory.
|
||||
|
||||
---
|
||||
|
||||
<img align="center" src="https://github.com/SRHTNIN/RepoAssets/blob/main/SaraSortd/Banners/Dependencies.png" width="100%" alt="Dependencies"/>
|
||||
|
||||
|
||||
python
|
||||
|
||||
toml: Use ```pip install toml``` to install toml.
|
||||
|
||||
---
|
||||
|
||||
<img align="center" src="https://github.com/SRHTNIN/RepoAssets/blob/main/SaraSortd/Banners/Installation.png" width="100%" alt="Installation"/>
|
||||
|
||||
|
||||
Here's an [installation video](https://youtu.be/QkMZVSJ-PLQ?si=Nd20jDyHT7CN6Ztb) on Linux.
|
||||
|
||||
Here's a step-by-step tutorial (in case you don't want to watch the video).
|
||||
|
||||
1. Install ZIP-file by clicking the green "Code" button on the top right, then clicking "Download Zip".
|
||||
2. Unzip ZIP-file wherever you want the program to live.
|
||||
3. Edit your config files to your liking. Make sure to edit your paths! (E.G. RootDir = "/home/janedoe/Programs/SaraSortd")
|
||||
4. Navigate to the new SaraSortd directory in your terminal (CMD / PowerShell on Windows).
|
||||
5. Run ```python SaraSortd.py``` to run the program. (This will make new directories for you.)
|
||||
6. Edit your new output directories' configs.
|
||||
|
||||
---
|
||||
|
||||
<img align="center" src="https://github.com/SRHTNIN/RepoAssets/blob/main/SaraSortd/Banners/ConfigInfo.png" width="100%" alt="Config Info"/>
|
||||
|
||||
<img align="center" src="https://github.com/SRHTNIN/RepoAssets/blob/main/SaraSortd/Banners/GlobalConf.png" width="100%" alt="GlobalConf"/>
|
||||
|
||||
|
||||
```
|
||||
Title = "SaraSortd Config" # NOTE: Do not change the title. This is so that the program knows which config file is which.
|
||||
|
||||
Version = "7.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.
|
||||
|
||||
SilentMode = 0 # If SaraSortd should write things it does, to the terminal.
|
||||
|
||||
SortTimer = 3 # How many seconds it takes for SaraSortd to check input directories for new files to sort.
|
||||
|
||||
DotFiles = 0 # If SaraSortd should sort files that begin with ".". This is mainly for linux users, since hidden files always have "." in front of them.
|
||||
|
||||
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 the config templates. 0 is no, 1 is yes.
|
||||
|
||||
[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.
|
||||
|
||||
NextChar = "&" # The next available character. If A already exists, B will be used.
|
||||
|
||||
Parent = "@" # The name of the parent directory.
|
||||
|
||||
OrgFileName = "\~" # The original name of the sorted file. If "blahblah.txt" gets sorted, "~" would be equal to "blahblah".
|
||||
|
||||
OrgFileType = "^" # The original file type of the sorted file. If "example.png" gets sorted, "^" would be equal to ".png".
|
||||
|
||||
Year = "[y]" # The current year, E.G. "2026".
|
||||
|
||||
Month = "[m]" # The date of the current month, E.G. "03".
|
||||
|
||||
Day = "[d]" # The date of the current day, E.G. "27".
|
||||
|
||||
Hour = "[h]" # The current hour, E.G. "12".
|
||||
|
||||
Minute = "[n]" # The current minute, E.G. "44".
|
||||
|
||||
Second = "[s]" # The current second, E.G. "11".
|
||||
|
||||
VarCall = "%%" # The characters used at the start and end of variable calls. The first character is to the left; second is to the right. NOTE: If any parameters in the config uses just "%%", it gets a variable from the program itself, not from the config.
|
||||
|
||||
[DirectoryPaths]
|
||||
RootDir = "Unset" # A variable directory. This doesn't NEED to exist for the program to work. It's more of a shorthand for other paths to use! You could add more of these. E.G: Add ImageDir = "%RootDir%/Images", then you could set OutputDir to be "%ImageDir%".
|
||||
|
||||
InputDir = ["%RootDir%"] # If files get put here, they'll be sorted. This is a list, so you can add multiple. E.G: ["%RootDir%", "%RootDir%/input"]
|
||||
|
||||
OutputDir = ["%RootDir%/Output"] # Where sorted files go. This is a list, so you can add multiple. E.G: ["%RootDir%/Output", "%RootDir%/Output2"]. The output directories have separate config files.
|
||||
|
||||
LogDir = "%RootDir%/.Logs" # Where log files from SaraSortd go.
|
||||
|
||||
FailedDir ="%RootDir%/.Failed" # For files that failed to be sorted.
|
||||
|
||||
[Names]
|
||||
LogFileName = "[y].[m].[d]._*" # Name for log files.
|
||||
|
||||
DirConfName = ".@Config" # Name for config files for directories.
|
||||
|
||||
FileHistoryName = ".@History" # Name for file history files. This keeps track of sorted files if an input and output are the same directory.
|
||||
|
||||
[Log]
|
||||
All = "[h]:[n]:[s] | " # What to put at the start of all lines in Log file.
|
||||
|
||||
Start = "Started: SaraSortd" # When SaraSortd starts.
|
||||
|
||||
NotStart = "Error: Failed to start SaraSortd." # When SaraSortd fails to start for some reason.
|
||||
|
||||
Stop = "\nStopped SaraSortd." # When SaraSortd stops for whatever reason. Usually when you interrupt it in the terminal you ran it in.
|
||||
|
||||
MatchPattern = "Checking %%." # When a file that's trying to be sorted gets checked against a pattern.
|
||||
# %% here is the file against the pattern. E.G: "picture.png against *.jpg"
|
||||
|
||||
Sorted = "Sorted: %%." # When a file gets sorted and where.
|
||||
# %% here is the oldfile to the newfile, E.G: "picture.png to SortedPicture.png".
|
||||
|
||||
NotSorted = "Error: Failed to sort %%. No valid output directory." # When a file from an input directory fails to be sorted to an output directory.
|
||||
# %% here is the path of the file. E.G: "/home/janedoe/picture.png".
|
||||
|
||||
ValueSet = "Set: %%." # When a value in a config is set.
|
||||
# %% here is the parameter and what it got set to. E.G: "Title to TestDir Config File".
|
||||
|
||||
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".
|
||||
|
||||
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".
|
||||
```
|
||||
---
|
||||
|
||||
<img align="center" src="https://github.com/SRHTNIN/RepoAssets/blob/main/SaraSortd/Banners/OutputDirConf.png" width="100%" alt="OutputDirConf"/>
|
||||
|
||||
|
||||
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" # NOTE: Do not change the title. This is so that the program knows which config file is which.
|
||||
|
||||
Version = "7.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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
Unzip = [] # What type of files this output directory should try to unzip. E.G:
|
||||
# Unzip = ["zip", "tar.gz"] would unzip .zip files and .tar files. This pairs insanely well with input directories' config's "SortDirs" parameter.
|
||||
|
||||
[[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:
|
||||
|
||||
# [[Files]]
|
||||
# Pattern = "*.png"
|
||||
# NewFileName = "GoodImage^"
|
||||
# NextNum = 1
|
||||
# NextChar = "A"
|
||||
# CaseSensitive = 0
|
||||
# [[Files]]
|
||||
# Pattern = "*.jpg"
|
||||
# NewFileName = "BetterImage^"
|
||||
# NextNum = 1
|
||||
# NextChar = "A"
|
||||
# CaseSensitive = 0
|
||||
# Overwrite = 1
|
||||
|
||||
# Will sort .png files to this directory and rename them to "GoodImage.png", but also sort .jpg files into this directory yet rename those to "BetterImage.jpg".
|
||||
|
||||
Pattern = "*" # A pattern used to sort files to this directory. * is a wildcard; ? is a one-character wildcard. E.G: if Pattern is "*.png", all files ending with .png will end up here.
|
||||
|
||||
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 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. 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.
|
||||
|
||||
Overwrite = 1 # Whether this specific file type can be overwritten by others of the same type. 0 is no, 1 is yes.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
<img align="center" src="https://github.com/SRHTNIN/RepoAssets/blob/main/SaraSortd/Banners/InputDirConf.png" width="100%" alt="InputDirConf"/>
|
||||
|
||||
|
||||
```
|
||||
Title = "Unset" # NOTE: Do not change the title. This is so that the program knows which config file is which.
|
||||
|
||||
Version = "7.0"
|
||||
|
||||
ParentDir = "Unset" # The name of this directory. It gets automatically updated when this config gets copied to an output directory.
|
||||
|
||||
SortDirs = 0 # If the input directory should be allowed to sort directories within it. Automatically uses .zip to move directories.
|
||||
|
||||
[[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.
|
||||
```
|
||||
|
||||
---
|
||||
+232
-76
@@ -6,7 +6,9 @@ import shutil
|
||||
import time
|
||||
import toml
|
||||
|
||||
ConfPath = "./Config.toml"
|
||||
# Version = "7.0"
|
||||
|
||||
ConfPath = "./GlobalConf.toml"
|
||||
|
||||
Conf = None
|
||||
ConfVars = None
|
||||
@@ -166,11 +168,11 @@ def Parse(
|
||||
ConfVars["OrgFileName"]: str(OrgFileName),
|
||||
ConfVars["OrgFileType"]: str(OrgFileType),
|
||||
ConfVars["Year"]: str(Now.year),
|
||||
ConfVars["Month"]: str(Now.month),
|
||||
ConfVars["Day"]: str(Now.day),
|
||||
ConfVars["Hour"]: str(Now.hour),
|
||||
ConfVars["Minute"]: str(Now.minute),
|
||||
ConfVars["Second"]: str(Now.second),
|
||||
ConfVars["Month"]: str(Now.month).rjust(2, "0"),
|
||||
ConfVars["Day"]: str(Now.day).rjust(2, "0"),
|
||||
ConfVars["Hour"]: str(Now.hour).rjust(2, "0"),
|
||||
ConfVars["Minute"]: str(Now.minute).rjust(2, "0"),
|
||||
ConfVars["Second"]: str(Now.second).rjust(2, "0"),
|
||||
ConfVars["VarCall"]: str(VarCall),
|
||||
}
|
||||
|
||||
@@ -188,6 +190,23 @@ def Parse(
|
||||
|
||||
|
||||
def Clone(Source, Destination, NewName, Delete = False):
|
||||
if (os.path.dirname(Source) == Destination):
|
||||
FileHistoryPath = f"{Destination}/{Parse(ConfNames["FileHistoryName"], Parent = os.path.basename(Destination))}.toml"
|
||||
print("FileHistoryPath:",FileHistoryPath)
|
||||
|
||||
if not os.path.exists(FileHistoryPath):
|
||||
with open(FileHistoryPath, "w", encoding = "utf-8") as HistoryFile:
|
||||
toml.dump({"Title": f"{os.path.basename(Destination)} History", "History": []}, HistoryFile)
|
||||
|
||||
HistoryFileData = toml.load(FileHistoryPath)
|
||||
if (NewName not in HistoryFileData["History"]):
|
||||
HistoryFileData["History"].append(NewName)
|
||||
with open(FileHistoryPath, "w", encoding = "utf-8") as HistoryFile:
|
||||
toml.dump(HistoryFileData, HistoryFile)
|
||||
|
||||
os.rename(Source, os.path.join(Destination, NewName))
|
||||
return
|
||||
|
||||
Dir(Destination, Output = False, CopyConf = False)
|
||||
shutil.copy2(Source, Destination)
|
||||
|
||||
@@ -198,26 +217,44 @@ def Clone(Source, Destination, NewName, Delete = False):
|
||||
os.remove(Source)
|
||||
|
||||
|
||||
def Dir(Path, Output = True, CopyConf = True):
|
||||
def Dir(Path, Output = True, CopyConf = "OutputDirConf.toml"):
|
||||
ParentName = os.path.basename(Path)
|
||||
os.makedirs(Path, exist_ok=True)
|
||||
|
||||
if CopyConf:
|
||||
NewDirConf = f"{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml"
|
||||
if Conf["OverwriteDirConf"] == 1 or not os.path.exists(
|
||||
os.path.join(f"{Path}/{NewDirConf}")
|
||||
):
|
||||
Clone("DirConfig.toml", Path, NewDirConf)
|
||||
UpdateConf(
|
||||
f"{Path}/{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
|
||||
"ParentDir",
|
||||
ParentName,
|
||||
)
|
||||
UpdateConf(
|
||||
f"{Path}/{Parse(String = ConfNames['DirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
|
||||
"Title",
|
||||
f"{ParentName} Config",
|
||||
)
|
||||
if "Out" in CopyConf:
|
||||
NewDirConf = f"{Parse(String = ConfNames['OutDirConfName'], 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['OutDirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
|
||||
"ParentDir",
|
||||
ParentName,
|
||||
)
|
||||
|
||||
UpdateConf(
|
||||
f"{Path}/{Parse(String = ConfNames['OutDirConfName'], Path = ConfPath, Parent = ParentName)}.toml",
|
||||
"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:
|
||||
ParsedPath = Parse(String = Path)
|
||||
@@ -247,13 +284,13 @@ def DecideNewPath(FilePath):
|
||||
|
||||
ParentName = os.path.basename(Output)
|
||||
|
||||
DirConfName = Parse(String = ConfNames["DirConfName"], Path = ConfPath, Parent = ParentName)
|
||||
DirConfPath = f"{Output}/{DirConfName}.toml"
|
||||
OutDirConfName = Parse(String = ConfNames["OutDirConfName"], Path = ConfPath, Parent = ParentName)
|
||||
OutDirConfPath = f"{Output}/{OutDirConfName}.toml"
|
||||
|
||||
ValidInputDirs = GetConf("ValidInputDirs", DirConfPath)
|
||||
ValidInputDirs = GetConf("ValidInputDirs", OutDirConfPath)
|
||||
|
||||
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}")
|
||||
LogWrite(TextOutput)
|
||||
@@ -263,13 +300,12 @@ def DecideNewPath(FilePath):
|
||||
if (InputDirValid):
|
||||
break
|
||||
|
||||
if not os.path.exists(DirConfPath) or not InputDirValid:
|
||||
if not os.path.exists(OutDirConfPath) or not InputDirValid:
|
||||
continue
|
||||
|
||||
|
||||
OutputFiles = 0
|
||||
|
||||
FileLimitConf = GetConf("FileLimit", DirConfPath)
|
||||
FileLimitConf = GetConf("FileLimit", OutDirConfPath)
|
||||
|
||||
if FileLimitConf > 0:
|
||||
for OutputFile in os.listdir(Output):
|
||||
@@ -281,7 +317,7 @@ def DecideNewPath(FilePath):
|
||||
if OutputFiles >= FileLimitConf:
|
||||
continue
|
||||
|
||||
FileConf = GetConf("Files", DirConfPath)
|
||||
FileConf = GetConf("Files", OutDirConfPath)
|
||||
|
||||
if not FileConf:
|
||||
continue
|
||||
@@ -302,30 +338,63 @@ def DecideNewPath(FilePath):
|
||||
if Match:
|
||||
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)):
|
||||
continue
|
||||
|
||||
if ConfVars["NextNum"] in NewFileName:
|
||||
UpdateConf(
|
||||
DirConfPath,
|
||||
"NextNum",
|
||||
(int(GetConf("NextNum", DirConfPath)) + 1),
|
||||
)
|
||||
if ConfVars["NextNum"] in File["NewFileName"]:
|
||||
ConfData = toml.load(OutDirConfPath)
|
||||
Width = len(File["NextNum"])
|
||||
NewNum = str((int(File["NextNum"]) + 1)).rjust(Width, "0")
|
||||
print(File["NextNum"],"=>",NewNum)
|
||||
|
||||
if ConfVars["NextChar"] in NewFileName:
|
||||
CurrentChar = GetConf("NextChar", DirConfPath)
|
||||
if CurrentChar and len(CurrentChar) == 1 and CurrentChar.isalpha():
|
||||
NewChar = chr(((ord(CurrentChar.upper()) - 65 + 1) % 26) + 65)
|
||||
UpdateConf(DirConfPath, "NextChar", NewChar)
|
||||
for Item in ConfData.get("Files", []):
|
||||
if Item.get("Pattern") == File["Pattern"]:
|
||||
Item["NextNum"] = NewNum
|
||||
break
|
||||
|
||||
with open(OutDirConfPath, "w", encoding="utf-8") as ConfFile:
|
||||
toml.dump(ConfData, ConfFile)
|
||||
|
||||
TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextNum to {NewNum}")
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
|
||||
if ConfVars["NextChar"] in File["NewFileName"]:
|
||||
CurrentChar = File["NextChar"]
|
||||
CurrentChar = CurrentChar.upper()
|
||||
Result = list(CurrentChar)
|
||||
|
||||
Count = len(Result) - 1
|
||||
|
||||
while Count >= 0:
|
||||
if Result[Count] == "Z":
|
||||
Result[Count] = "A"
|
||||
Count -= 1
|
||||
|
||||
else:
|
||||
Result[Count] = chr(ord(Result[Count]) + 1)
|
||||
break
|
||||
|
||||
else:
|
||||
Result.insert(0, "A")
|
||||
|
||||
NewChar = "".join(Result)
|
||||
|
||||
ConfData = toml.load(OutDirConfPath)
|
||||
|
||||
for Item in ConfData.get("Files", []):
|
||||
if Item.get("Pattern") == File["Pattern"]:
|
||||
Item["NextChar"] = NewChar
|
||||
break
|
||||
|
||||
with open(OutDirConfPath, "w", encoding="utf-8") as ConfFile:
|
||||
toml.dump(ConfData, ConfFile)
|
||||
|
||||
TextOutput = Parse(String = ConfLog["ValueSet"], VarCall = f"NextChar to {NewChar}")
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
|
||||
return f"{Output}/{NewFileName}"
|
||||
|
||||
@@ -346,24 +415,24 @@ def Sort(FilePath):
|
||||
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,
|
||||
)
|
||||
if (GetConf("DeleteOrg", f"{NewDirPath}/{Parse(String = ConfNames['OutDirConfName'], Parent = (os.path.basename(NewDirPath)))}.toml") == 1):
|
||||
Delete = True
|
||||
|
||||
TextOutput = Parse(
|
||||
String = ConfLog["Sorted"], VarCall = f"{FilePath} to {NewDirPath}/{NewName}"
|
||||
)
|
||||
else:
|
||||
Delete = False
|
||||
|
||||
try:
|
||||
Clone(FilePath, NewDirPath, NewName, Delete)
|
||||
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}")
|
||||
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)
|
||||
@@ -381,12 +450,29 @@ def Init():
|
||||
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)
|
||||
Dir(InputDir, Output = False, CopyConf = "InputDirConf.toml")
|
||||
|
||||
for Output in ConfDirs["OutputDir"]:
|
||||
Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(Output)))
|
||||
Dir(Output)
|
||||
|
||||
OutDirConfPath = f"{Output}/{Parse(String = ConfNames["OutDirConfName"], Parent = os.path.basename(Output))}.toml"
|
||||
ConfData = toml.load(OutDirConfPath)
|
||||
|
||||
for Item in ConfData.get("Files", []):
|
||||
Character = re.escape(ConfVars["NextChar"])
|
||||
Matches = re.findall(f"{Character}+", Item["NewFileName"])
|
||||
Width = max((len(Match) for Match in Matches), default=0)
|
||||
|
||||
if Width > 0:
|
||||
Item["NextChar"] = Item["NextChar"].upper().rjust(Width, "A")
|
||||
|
||||
with open(OutDirConfPath, "w", encoding = "utf-8") as ConfFile:
|
||||
toml.dump(ConfData, ConfFile)
|
||||
|
||||
TextOutput = Parse(String = ConfLog["Start"], Path = ConfPath)
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
|
||||
Main()
|
||||
|
||||
else:
|
||||
@@ -395,39 +481,109 @@ 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 'GlobalConf.toml' is in the same directory as 'SaraSortd.py'")
|
||||
|
||||
|
||||
def Main():
|
||||
for Output in ConfDirs["OutputDir"]:
|
||||
Output = Parse(String = Output, Parent = os.path.basename(os.path.dirname(Output)))
|
||||
Dir(Output)
|
||||
|
||||
try:
|
||||
while True:
|
||||
for Input in ConfDirs["InputDir"]:
|
||||
RecurseDir = False
|
||||
|
||||
InputPath = Parse(Input)
|
||||
|
||||
if not os.path.exists(InputPath):
|
||||
continue
|
||||
|
||||
InputDirConfPath = f"{InputPath}/{Parse(ConfNames["InDirConfName"], Parent = os.path.basename(InputPath))}.toml"
|
||||
InputDirConf = toml.load(InputDirConfPath)
|
||||
|
||||
for Output in ConfDirs["OutputDir"]:
|
||||
OutputPath = Parse(Output)
|
||||
OutDirConfPath = f"{OutputPath}/{Parse(ConfNames["OutDirConfName"], Parent = os.path.basename(OutputPath))}.toml"
|
||||
|
||||
if len(GetConf("Unzip", OutDirConfPath)) >= 1:
|
||||
ZipTypes = GetConf("Unzip", OutDirConfPath)
|
||||
for OutputFile in os.listdir(OutputPath):
|
||||
if OutputFile.startswith("."):
|
||||
continue
|
||||
|
||||
for ZipType in ZipTypes:
|
||||
print(ZipType)
|
||||
if (OutputFile.lower()).endswith((ZipType).lower()):
|
||||
shutil.unpack_archive(f"{OutputPath}/{OutputFile}", OutputPath)
|
||||
TextOutput = Parse(String = ConfLog["Unzipping"], VarCall = f"{OutputPath}/{OutputFile}")
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
|
||||
try:
|
||||
os.remove(f"{OutputPath}/{OutputFile}")
|
||||
|
||||
except PermissionError:
|
||||
TextOutput = Parse(String = ConfLog["NoPermission"], VarCall = f"remove {OutputPath}/{OutputFile}")
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
continue
|
||||
|
||||
if (OutputPath == InputPath):
|
||||
RecurseDir = True
|
||||
FileHistoryPath = f"{InputPath}/{Parse(ConfNames["FileHistoryName"], Parent = os.path.basename(InputPath))}.toml"
|
||||
|
||||
if not os.path.exists(FileHistoryPath):
|
||||
with open(FileHistoryPath, "w", encoding = "utf-8") as HistoryFile:
|
||||
toml.dump({"Title": f"{os.path.basename(InputPath)} History", "History": [] }, HistoryFile)
|
||||
|
||||
for FileName in os.listdir(InputPath):
|
||||
FilePath = os.path.join(InputPath, FileName)
|
||||
FilePath = f"{InputPath}/{FileName}"
|
||||
if os.path.isdir(FilePath) and InputDirConf["SortDirs"] == 0:
|
||||
continue
|
||||
|
||||
FileName = os.path.basename(FilePath)
|
||||
if FileName.startswith(".") and Conf["DotFiles"] == 0:
|
||||
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:
|
||||
shutil.rmtree(FilePath, ignore_errors=True)
|
||||
|
||||
except PermissionError:
|
||||
TextOutput = Parse(String = ConfLog["NoPermission"], VarCall = f"remove directory {InputPath}/{FileName}")
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
continue
|
||||
|
||||
FilePath = f"{FilePath}.zip"
|
||||
|
||||
if RecurseDir:
|
||||
HistoryFile = toml.load(FileHistoryPath)
|
||||
|
||||
if (Parse(FileName, Parent = os.path.basename(InputPath)) in HistoryFile["History"]):
|
||||
continue
|
||||
|
||||
if os.path.isfile(FilePath):
|
||||
FileName = os.path.basename(FilePath)
|
||||
if FileName.startswith(".") and Conf["DotFiles"] == 0:
|
||||
continue
|
||||
Sort(FilePath)
|
||||
|
||||
time.sleep(Conf.get("CheckInput", 10))
|
||||
time.sleep(Conf.get("SortTimer", 10))
|
||||
|
||||
except KeyboardInterrupt:
|
||||
TextOutput = GetConf("Stop", ConfPath)
|
||||
LogWrite(TextOutput)
|
||||
Speak(TextOutput)
|
||||
|
||||
|
||||
Init()
|
||||
Reference in new issue
Block a user