Vidir

Revision as of 04:20, 9 June 2020 by rosettacode>Violazoli (vidir, dir, edit)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Create the famous "vidir" progam in your favorite programming language!

Vidir is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

The original "vidir" was written in Perl, and it is the part of the socalled "moreutils" package, whomabout you can read in details at here: https://joeyh.name/code/moreutils/

Furor

<lang Furor>

      1. sysinclude dir.uh
      2. define SEPARATOR 9
  1. g argc 3 < { "." }{ 2 argv } sto mypath

@mypath 'd !istrue { ."The given directory doesn't exist! Exited.\n" end } 6 '- pidstr sto pidstring @mypath getdir { ."Cannot load the dir! Aborted.\n" end } sto mydir mypath per // If the end is not a '/' char, then add to... 10 mem sto aktfilename 10 mem sto neworiginalname tömb @mydir dirlist filtered tömb SEPARATOR [ #s 0 [-] "R" != 0 [-] "D" != #g & { dropline }{ 2 dropfield 2 dropfield } getline ] "/tmp/furordiredit_tempfile-" sto myfilename

  1. s

@pidstring sum myfilename ".txt" sum myfilename filtered @myfilename listtofile // print the list into a temporary file "EDITOR" env sto mycommand " " sum mycommand @myfilename sum mycommand @mycommand shell // execute the command editedlist @myfilename filetolist filtered SEPARATOR externalloop: ![ // Loop for the original list [-?] !{ dropline } // If empty lines occured...

  1. s

zero foundflag editedlist SEPARATOR ![ // Loop for the edited list // searching for the originaltype and originalnumber: 0 [-] 0 [-]§externalloop != { dropline } 1 [-] 1 [-]§externalloop != { dropline } 2 [-] 2 [-]§externalloop != { 2 [-] sbr §aktfilenamecreate neworiginalname @mypath = 2 [-]§externalloop sum neworiginalname @neworiginalname @aktfilename rename ."Renamed  : " @neworiginalname print ." ==> " @aktfilename printnl } one foundflag [>] ] // end for the editedlist-loop @foundflag !{ // No file or dir. In this case it must be deleted: 0 [-]§externalloop "D" == { // directory 2 [-] sbr §aktfilenamecreate @aktfilename rmdir ."Deleted  : " @aktfilename printnl dropline } 0 [-]§externalloop "R" == { // regular file 2 [-] sbr §aktfilenamecreate @aktfilename removefile ."Deleted  : " @aktfilename printnl dropline } }

] // End of the loop for the original list

@myfilename removefile end aktfilenamecreate: aktfilename @mypath = sum aktfilename rts

{ „mydir” } { „tömb” } { „mypath” } { „filtered” } { „pidstring” } { „myfilename” } { „mycommand” } { „editedlist” } { „foundflag” } { „aktfilename” } { „neworiginalname” }

</lang>