Damit kann man sich z. B. für bestimmte Bildserien gezielt zum Vorsortieren einen Ordner anlegen.
Ich möchte darauf hinweisen, dass das Skript Daten auf die SD-Karte schreibt. Deshalb sollte man sich genau überlegen, was man tut. Nichtzulässige Ordnernamen könnten zu Dateiverlusten führen!
--------------------------------------------------------------------------------------------------------------------------------------------
Funktionsweise:
Im Skript-Menü kann als Parameter die Wiederholrate der Tastatur bestimmt werden.
1. Konsolen-Fenster
[SET] Eingabe Name
[DISP] Verzeichnis wählen
[DOWN] Erstelle Ordner
[MENU] Ende
2. Eingabe Name
Die Routine ist bekannt - siehe hier
[<-][->] Auswahl: Zeichen 1 Schritt
[SET] Zeichen schreiben
[+/-] Zeichen löschen
[UP] Auswahl: kleine Buchstaben, große Buchstaben, Zahlen und Sonderzeichen
[DOWN] Rücksprung auf erstes Zeichen (a)
[ZOOM in/out] Auswahl: Zeichen 5 Schritte
[MENU] fertig und weiter
3. Verzeichnis wählen
[UP] im Verzeicnis einen Schritt weiter
[DOWN] im Verzeichnis einen Schritt zurück
[SET] Auswählen
[MENU] fertig und weiter
4. Erstelle Ordner
[SET] Ordner wird erstellt
Bei allen Untermenüs gelangt man nach Fertigstellung der Funktion durch einen Tastenklick wieder in das Hauptmenü.
Syntax: [ Download ] [ Verstecken ]
Benutze Lua Syntax Highlighting
--[[
@title dir input
@param f key delay
@default f 150
]]
function button()
local x = 0
repeat
wait_click(key_delay)
if is_pressed "set" then
key = "SET"
x = 1
end
if is_pressed "erase" then
key = "ERASE"
x = 1
end
if is_pressed "display" then
key = "DISP"
x = 1
end
if is_pressed "menu" then
key = "MENU"
x = 1
end
if is_pressed "up" then
key = "UP"
x = 1
end
if is_pressed "down" then
key = "DOWN"
x = 1
end
if is_pressed "left" then
key = "LEFT"
x = 1
end
if is_pressed "right" then
key = "RIGHT"
x = 1
end
if is_pressed "zoom_in" then
key = "ZOOM_IN"
x = 1
end
if is_pressed "zoom_out" then
key = "ZOOM_OUT"
x = 1
end
until x == 1
set_led (8,1)
sleep (10)
set_led (8,0)
end
function get_state(file_name)
state_is = {}
local r = os.stat(file_name)
if r then
local keys={ "dev", "mode", "size", "atime", "mtime",
"ctime", "blksize", "blocks", "attrib","is_dir","is_file",}
for k,v in ipairs(keys) do
state_is[v] = r[v]
end
end
return state_is
end
function read_dir()
local i = 1
repeat
dir = os.listdir(path, true)
table.sort(dir)
count = table.getn(dir)
name = dir[i]
get_state(path.."/"..name)
if state_is.is_file == true then
size = tostring(state_is.size/1024).." kB"
elseif state_is.is_dir == true then
size = "[dir]"
else
size = ""
end
if name == "." then name = "[Wurzelverzeichnis]" end
if name == ".." then name = "[zurück]" end
cls()
if i<10 then
ii = "0"..i
else
ii = i
end
print(path.."/")
print(ii..".",name)
print(" ",size)
print("-------------------------")
print("[UP] [DOWN] [SET] [MENU]")
button()
if key == "DOWN" then
i=i+1
if i > count then i=1 end
end
if key == "UP" then
i=i-1
if i < 1 then i= count end
end
if key == "SET" then
if state_is.is_dir == true then
path_count = path_count + 1
path = path.."/"..name
path_t[path_count] = path
i=1
end
if state_is.is_file == true then
file_name = name
key = "MENU"
end
if name == "[Wurzelverzeichnis]" then
path = path_t[1]
i=1
end
if name == "[zurück]" then
path_count = path_count - 1
if path_count < 1 then path_count = 1 end
path = path_t[path_count]
i=1
end
end
until key == "MENU"
end
function tabToStr()
output=table.concat(word)
end
function input()
cls()
abc_lower = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
"q","r","s","t","u","v","w","x","y","z"}
abc_upper = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
"Q","R","S","T","U","V","W","X","Y","Z"}
abc_spec = {"0","1","2","3","4","5","6","7","8","9",",",".","-",";",":","_",
"/","ü","Ü","ö","Ö","ä","Ä","#","|"," "}
word = {}
a=0
b=0
actChar=""
repeat
print("-------------------------")
print("[<-][->][SET] [+/-][MENU]")
print("[ZOOM in/out] [UP][DOWN]")
button()
cls()
if key == "RIGHT" then a=a+1 end
if key == "LEFT" then a=a-1 end
if key == "UP" then b=b+1 end
if key == "DOWN" then a=1 end
if key == "ZOOM_IN" then a=a+5 end
if key == "ZOOM_OUT" then a=a-5 end
if a >= 27 then a=1 end
if a <= 0 then a=26 end
if b>=3 then b=0 end
if b==0 then
actChar=abc_lower[a]
char_info="klein"
end
if b==1 then
actChar=abc_upper[a]
char_info="groß"
end
if b==2 then
actChar=abc_spec[a]
char_info="Zahlen"
end
print(char_info..": "..actChar)
if key == "SET" then table.insert(word,actChar) end
if key == "ERASE" then table.remove(word) end
tabToStr()
print("input: "..output)
until key == "MENU"
end
function wait_key()
print()
print("----Drücke-eine-Taste----")
button()
if key == "MENU" then sleep(500) end
key = ""
end
-- start script
key_delay = f
file_name = ""
path = "A"
path_count = 1
path_t = {}
path_t[path_count] = path
output = ""
repeat
cls()
print("[SET] Eingabe Name")
print("[DISP] Verzeichnis wählen")
print("[DOWN] Erstelle Ordner")
print("[MENU] Ende")
button()
if key == "SET" then
input()
cls()
print("Name:",output)
wait_key()
end
if key == "DISP" then
read_dir()
cls()
print("Pfad:",path)
print(file_name)
wait_key()
end
if key == "DOWN" then
if output ~= "" then
new_dir = path.."/"..output
os.mkdir(new_dir)
cls()
print(new_dir,"erstellt")
wait_key()
else
cls()
print("Ordnername fehlt!")
wait_key()
end
end
until key == "MENU"
@title dir input
@param f key delay
@default f 150
]]
function button()
local x = 0
repeat
wait_click(key_delay)
if is_pressed "set" then
key = "SET"
x = 1
end
if is_pressed "erase" then
key = "ERASE"
x = 1
end
if is_pressed "display" then
key = "DISP"
x = 1
end
if is_pressed "menu" then
key = "MENU"
x = 1
end
if is_pressed "up" then
key = "UP"
x = 1
end
if is_pressed "down" then
key = "DOWN"
x = 1
end
if is_pressed "left" then
key = "LEFT"
x = 1
end
if is_pressed "right" then
key = "RIGHT"
x = 1
end
if is_pressed "zoom_in" then
key = "ZOOM_IN"
x = 1
end
if is_pressed "zoom_out" then
key = "ZOOM_OUT"
x = 1
end
until x == 1
set_led (8,1)
sleep (10)
set_led (8,0)
end
function get_state(file_name)
state_is = {}
local r = os.stat(file_name)
if r then
local keys={ "dev", "mode", "size", "atime", "mtime",
"ctime", "blksize", "blocks", "attrib","is_dir","is_file",}
for k,v in ipairs(keys) do
state_is[v] = r[v]
end
end
return state_is
end
function read_dir()
local i = 1
repeat
dir = os.listdir(path, true)
table.sort(dir)
count = table.getn(dir)
name = dir[i]
get_state(path.."/"..name)
if state_is.is_file == true then
size = tostring(state_is.size/1024).." kB"
elseif state_is.is_dir == true then
size = "[dir]"
else
size = ""
end
if name == "." then name = "[Wurzelverzeichnis]" end
if name == ".." then name = "[zurück]" end
cls()
if i<10 then
ii = "0"..i
else
ii = i
end
print(path.."/")
print(ii..".",name)
print(" ",size)
print("-------------------------")
print("[UP] [DOWN] [SET] [MENU]")
button()
if key == "DOWN" then
i=i+1
if i > count then i=1 end
end
if key == "UP" then
i=i-1
if i < 1 then i= count end
end
if key == "SET" then
if state_is.is_dir == true then
path_count = path_count + 1
path = path.."/"..name
path_t[path_count] = path
i=1
end
if state_is.is_file == true then
file_name = name
key = "MENU"
end
if name == "[Wurzelverzeichnis]" then
path = path_t[1]
i=1
end
if name == "[zurück]" then
path_count = path_count - 1
if path_count < 1 then path_count = 1 end
path = path_t[path_count]
i=1
end
end
until key == "MENU"
end
function tabToStr()
output=table.concat(word)
end
function input()
cls()
abc_lower = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
"q","r","s","t","u","v","w","x","y","z"}
abc_upper = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
"Q","R","S","T","U","V","W","X","Y","Z"}
abc_spec = {"0","1","2","3","4","5","6","7","8","9",",",".","-",";",":","_",
"/","ü","Ü","ö","Ö","ä","Ä","#","|"," "}
word = {}
a=0
b=0
actChar=""
repeat
print("-------------------------")
print("[<-][->][SET] [+/-][MENU]")
print("[ZOOM in/out] [UP][DOWN]")
button()
cls()
if key == "RIGHT" then a=a+1 end
if key == "LEFT" then a=a-1 end
if key == "UP" then b=b+1 end
if key == "DOWN" then a=1 end
if key == "ZOOM_IN" then a=a+5 end
if key == "ZOOM_OUT" then a=a-5 end
if a >= 27 then a=1 end
if a <= 0 then a=26 end
if b>=3 then b=0 end
if b==0 then
actChar=abc_lower[a]
char_info="klein"
end
if b==1 then
actChar=abc_upper[a]
char_info="groß"
end
if b==2 then
actChar=abc_spec[a]
char_info="Zahlen"
end
print(char_info..": "..actChar)
if key == "SET" then table.insert(word,actChar) end
if key == "ERASE" then table.remove(word) end
tabToStr()
print("input: "..output)
until key == "MENU"
end
function wait_key()
print()
print("----Drücke-eine-Taste----")
button()
if key == "MENU" then sleep(500) end
key = ""
end
-- start script
key_delay = f
file_name = ""
path = "A"
path_count = 1
path_t = {}
path_t[path_count] = path
output = ""
repeat
cls()
print("[SET] Eingabe Name")
print("[DISP] Verzeichnis wählen")
print("[DOWN] Erstelle Ordner")
print("[MENU] Ende")
button()
if key == "SET" then
input()
cls()
print("Name:",output)
wait_key()
end
if key == "DISP" then
read_dir()
cls()
print("Pfad:",path)
print(file_name)
wait_key()
end
if key == "DOWN" then
if output ~= "" then
new_dir = path.."/"..output
os.mkdir(new_dir)
cls()
print(new_dir,"erstellt")
wait_key()
else
cls()
print("Ordnername fehlt!")
wait_key()
end
end
until key == "MENU"
Erstellt in 0.035 Sekunden, mit GeSHi 1.0.8.9