import opts
`{
-#include <errno.h>
+ #include <errno.h>
+ #include <string.h>
`}
# Local config
# Modify these according to your needs. It is also possible to have alternates
# using class refinment and a main calling to super.
class Config
+ # Is it configured? Change to "true" when the configuration has been
+ # adapted to your needs and setup
+ var is_configured = false
+
# Source directory where are the files to be sorted.
var source_dir = "~/Downloads/"
end
# Returns null on success
- fun file_rename_to(dest: String): nullable String import String::to_cstring,
- String::from_cstring, String as nullable `{
- int res = rename(String_to_cstring(recv), String_to_cstring(dest));
+ fun file_rename_to(dest: String): nullable String import String.to_cstring,
+ CString.to_s, String.as nullable `{
+ int res = rename(String_to_cstring(self), String_to_cstring(dest));
if (res == 0) return null_String();
- return String_as_nullable(new_String_from_cstring(strerror(errno)));
+ return String_as_nullable(CString_to_s(strerror(errno)));
`}
# Replace `~` by the path to the home diretory
fun replace_tilde: String
do
- var home_folder = "HOME".environ
- return replace("~", home_folder)
+ var match = search("~/")
+ if match != null and match.from == 0 then
+ var home_folder = "HOME".environ
+ return "{home_folder}/{substring(match.after, length)}"
+ else return self
end
end
-# Hack to keep track of the real directory name associated to this pattern
-redef class BM_Pattern
- var dir: String
+# Keeps track of the real directory name associated to this pattern
+class PatternWithDir
+ super BM_Pattern
+
+ var dir: String is noinit
init with_dir(motif, dir: String)
do
end
# build regexxes
- var patterns = new HashSet[BM_Pattern]
+ var patterns = new HashSet[PatternWithDir]
for dir in dirs_name do
- patterns.add new BM_Pattern.with_dir(dir, dir)
- patterns.add new BM_Pattern.with_dir(dir.replace(' ', "."), dir)
- patterns.add new BM_Pattern.with_dir(dir.replace(' ', "_"), dir)
+ patterns.add new PatternWithDir.with_dir(dir, dir)
+ patterns.add new PatternWithDir.with_dir(dir.replace(' ', "."), dir)
+ patterns.add new PatternWithDir.with_dir(dir.replace(' ', "_"), dir)
end
# compare source files with patterns and sort
end
var config = new Config
+if not config.is_configured then
+ print "Not configured, make sure you modify the script and set is_configured to true"
+ exit 1
+end
var sorter = new XySorter
# calculate cut off time using `elapsed_days` compared to now