Compare commits

...

3 Commits

Author SHA1 Message Date
bb1d56c950 Use absolute paths
Thanks windows
2025-10-01 14:05:20 +02:00
882713359d Add deploy script
Some other scripts expect it so here
2025-10-01 14:02:37 +02:00
a9b9e06324 Add context menu regedits 2025-10-01 14:02:16 +02:00
5 changed files with 40 additions and 13 deletions

1
deploy.sh Normal file
View File

@@ -0,0 +1 @@
go install .

2
go.mod
View File

@@ -1,4 +1,4 @@
module datesorter
module dategrouper
go 1.23.6

19
install_context_menu.reg Normal file
View File

@@ -0,0 +1,19 @@
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\Directory\shell\Group by date]
@="Group by date"
[HKEY_CURRENT_USER\Software\Classes\Directory\shell\Group by date\command]
@="C:\\Users\\administrator\\go\\bin\\dategrouper.exe \"%1\""
[HKEY_CURRENT_USER\Software\Classes\*\shell\Group by date]
@="Group by date"
[HKEY_CURRENT_USER\Software\Classes\*\shell\Group by date\command]
@="C:\\Users\\administrator\\go\\bin\\dategrouper.exe \"%1\""
[HKEY_CURRENT_USER\Software\Classes\AllFileSystemObjects\shell\Group by date]
@="Group by date"
[HKEY_CURRENT_USER\Software\Classes\AllFileSystemObjects\shell\Group by date\command]
@="C:\\Users\\administrator\\go\\bin\\dategrouper.exe %*"

23
main.go
View File

@@ -44,6 +44,7 @@ func (dp *DateParserISO) Parse(s string) (time.Time, error) {
func main() {
flag.Parse()
logger.InitFlag()
logger.Default = logger.Default.ToFile("dategrouper.log")
if flag.NArg() == 0 {
logger.Error("no files provided")
@@ -57,7 +58,6 @@ func main() {
files := flag.Args()
cyutils.WithWorkers(10, files, func(worker int, _ int, file string) {
workerlog := logger.Default.WithPrefix(fmt.Sprintf("worker=%d", worker))
filelog := workerlog.WithPrefix(fmt.Sprintf("file=%q", file))
@@ -68,25 +68,23 @@ func main() {
return
}
filelog.Info("date: %s", date)
datedir := fmt.Sprintf("%04d-%02d-%02d", date.Year(), date.Month(), date.Day())
dest := filepath.Join(datedir, file)
dir := filepath.Dir(file)
datedir := filepath.Join(dir, fmt.Sprintf("%04d-%02d-%02d", date.Year(), date.Month(), date.Day()))
dest := filepath.Join(datedir, filepath.Base(file))
filelog.Info("dest: %s", dest)
err = os.MkdirAll(datedir, 0755)
if err != nil {
filelog.Error("error creating directory: %s", err)
return
}
// Make sure file doesn't exist
destfile, err := os.Stat(dest)
if err == nil {
filelog.Info("dest file already exists: %s", destfile.Name())
return
} else {
if !os.IsNotExist(err) {
filelog.Error("error checking dest file: %s", err)
return
}
} else if !os.IsNotExist(err) {
filelog.Error("error checking dest file: %s", err)
return
}
filelog.Debug("opening input file")
@@ -99,16 +97,17 @@ func main() {
out, err := os.Create(dest)
if err != nil {
filelog.Error("error creating dest file: %s", err)
in.Close()
return
}
filelog.Info("copying file")
_, err = io.Copy(out, in)
in.Close()
out.Close()
if err != nil {
filelog.Error("error copying file: %s", err)
return
}
in.Close()
out.Close()
filelog.Info("removing original file")
err = os.Remove(file)

View File

@@ -0,0 +1,8 @@
Windows Registry Editor Version 5.00
[-HKEY_CURRENT_USER\Software\Classes\Directory\shell\Group by date]
[-HKEY_CURRENT_USER\Software\Classes\Directory\shell\Group by date\command]
[-HKEY_CURRENT_USER\Software\Classes\*\shell\Group by date]
[-HKEY_CURRENT_USER\Software\Classes\*\shell\Group by date\command]
[-HKEY_CURRENT_USER\Software\Classes\AllFileSystemObjects\shell\Group by date]
[-HKEY_CURRENT_USER\Software\Classes\AllFileSystemObjects\shell\Group by date\command]