Skip to content

Commit

Permalink
Working version
Browse files Browse the repository at this point in the history
  • Loading branch information
unquietwiki committed Oct 4, 2022
1 parent 4b945f9 commit f72e81c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.zip
nimcache/
bin/
sortplz.exe
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# sortplz

_sortplz_ is a simple file sorter. It takes targeted files, and moves them to subdirectories for further review.

**Usage:** sortplz -f _fromdir_ -t _todir_ -e _ext_

## TODO

- Sort by size
- Sort by name, not extension
- Colorful output
- Verbosity flag
- It'd be nice to have the files/extensions specified without a option.
2 changes: 1 addition & 1 deletion sortplz.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ installExt = @["nim"]

requires "nim >= 1.6.0"

const compile = "nim c -d:release --outdir:bin"
const compile = "nim c -d:release"
const linux_x64 = "--cpu:amd64 --os:linux -o:sortplz"
const windows_x64 = "--cpu:amd64 --os:windows -o:sortplz.exe"
const macosx_x64 = "-o:sortplz"
Expand Down
4 changes: 2 additions & 2 deletions src/config.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const
pkgTitle* = "sortplz"
pkgVersion* = "2022.10.03.1"
pkgAuthor* = "Michael Adams"
pkgVersion* = "2022.10.04.1"
pkgAuthor* = "Michael Adams, unquietwiki@gmail.com"
pkgDescription* = "Sort files into subdirectories, based on given criteria."
54 changes: 26 additions & 28 deletions src/sortplz.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Michael Adams, unquietwiki.com, 2022-10-03
import
std/os,
std/parseopt,
std/strutils
std/sequtils

# Config import
include
Expand All @@ -29,61 +29,59 @@ var
# Function to process & sort directory
proc processDir(ext: string) =

# Temporary variables
var newdir: string = ""
echo "Processing extension: ", ext

# Does the source directory exist?
if os.dirExists(fromdir) == false:
if not os.dirExists(fromdir):
quit(1)

# Does the destination directory exist?
if os.dirExists(todir) == false:
newdir = os.joinPath(todir, ext)
os.createDir(newdir)
var newdir: string = os.joinPath(todir, ext)
echo "Creating directory: ", newdir
os.createDir(newdir)

# Process the list of files in the source directory
for kind, path in walkDir(fromdir, relative = false, checkDir = false):
if kind == pcFile:
if path.endsWith(ext):
os.moveFile(path, newdir)
var searchpath = os.joinPath(fromdir,"*." & ext)
echo "Moving files: ", searchpath, " to ", newdir
for f in toSeq(os.walkFiles(searchpath)):
echo "Moving file: ", os.lastPathPart(f)
os.moveFile(f, newdir & os.DirSep & os.lastPathPart(f))

# Functions to display command line information
proc writeVersion() =
echo name, " ", version
echo description
echo "Maintainer(s): ", author

proc writeHelp() =
writeVersion()
echo "Usage: sortplz -f [fromdir] -t [todir] [ext] ..."
echo "Usage: sortplz -f [fromdir] -t [todir] -e [ext]"

# Parse command line
var p = initOptParser(@["--fromdir:string","-f:string","--todir:string","-t:string","--help","-h","--version","-v"],
shortNoVal = {'h','v'}, longNoVal = @["help","version"])

for kind, key, val in p.getopt():
for kind, key, val in getopt():
case kind
of cmdArgument:
echo "Loading extension: ", val
exts.add(val)
of cmdLongOption, cmdShortOption:
case key
of "ext", "e":
echo "Loading extension: ", val
exts.add(val)
of "fromdir", "f":
if val != "": fromdir = val
break
if val.len > 0: fromdir = val
echo "Source directory: ", fromdir
of "todir", "t":
if val != "": todir = val
break
if val.len > 0: todir = val
echo "Destination directory: ", todir
of "help", "h":
writeHelp()
quit(0)
of "version", "v":
writeVersion()
quit(0)
of cmdEnd: quit(0)

# debug
echo "DEBUG:", p.remainingArgs()
echo "DEBUG:", exts
of cmdArgument:
# TODO: there should be a list of extensions, vs -e
discard
of cmdEnd:
quit(0)

# Act on provided extensions
if exts.len < 1:
Expand Down

0 comments on commit f72e81c

Please sign in to comment.