Jump to content

Vidir: Difference between revisions

2,057 bytes added ,  4 years ago
m (→‎{{header|Raku}}: Bug fix, rename some variables minor tweaks)
Line 116:
 
</lang>
 
=={{header|Phix}}==
Should work on Windows and Linux. I have commented out all the actualy destructive statements.
<lang Phix>-- demo/rosetta/vidir.exw
string directory = ".",
editor = iff(platform()=WINDOWS?"notepad":"gedit"),
workfile = "vidir.txt"
-- filter = ""
--bool recursive = false,
-- overwrite = false,
-- verbose = false -- ,... etc
 
procedure process_command_line()
sequence cl = command_line()[3..$]
if length(cl) then
-- I assume you can figure out how to deal with eg
-- {`-d`,`C:\Users\Pete\Documents`,`-e`,`notepad++`}
?{"command line arguments (ignored)",cl}
end if
end procedure
 
process_command_line()
sequence d = dir(directory)
if d=-1 then
crash("no such directory")
end if
d = d[3..$] -- (drop "." and "..")
integer fn = open(workfile,"w")
for i=1 to length(d) do
printf(fn,"%d: %s\n",{i,d[i][D_NAME]})
end for
close(fn)
{} = system_exec(editor&" "&workfile)
object lines = get_text(workfile,GT_LF_STRIPPED)
integer last = 0
if lines=-1 then
crash("error reading edited file")
end if
for i=1 to length(lines) do
sequence r = scanf(lines[i],"%d: %s")
if r={} then
crash("error parsing line")
end if
{{integer line, string name}} = r
for last=last+1 to line-1 do
printf(1,"delete_file(%s)\n",{d[last][D_NAME]})
if not file_exists(d[last][D_NAME]) then ?9/0 end if
-- if not delete_file(d[last][D_NAME]) then
-- crash("error deleting file")
-- end if
end for
string prev = d[line][D_NAME]
if prev!=name then
printf(1,"rename_file(%s,%s)\n",{prev,name})
if not file_exists(prev) then ?9/0 end if
if file_exists(name) then ?9/0 end if
-- if name[2]=':' and name[1]!=prev[1] then
-- if not move_file(prev,name) then
-- crash(error moving file")
-- end if
-- elsif not rename_file(prev,name) then
-- crash("error renaming file")
-- end if
end if
last = line
end for
?"done"
{} = wait_key()</lang>
 
=={{header|Raku}}==
7,820

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.