// // XTREE.VDM Christian Ziemski 19.05.2002 // 26.05.2002 // 11.06.2004 // "Poor man's XTREE" // // >>> BETA-Version! Use with caution! <<< // // Sort a listing created by "DIR /S" by filename/path or ... // // Hotkeys for viewing and deleting files etc. See online help below (Shft-F1) // //--------------------------------------------------------------------- // // to do: //------- // sort by date: Problem: if the year has ony 2 digits (Win9x) the sort isn't correct // Reg_Push/Reg_Pop to save registers // How to choose a directory with only subdirs but now files in it? // how to determine the language of the OS? // more error handling // //--------------------------------------------------------------------- // // #90 testing flag // #91 language: 0 = english, 1 = german // #92 buf num of list // #93 sorting order // #96 buf num of loaded file // #97=Cur_Col of the 1st | // #98=Cur_Col of the 2nd | // //--------------------------------------------------------------------- if(Os_Type != 1){ // only for Windows version of VEDIT // (but should be possible to adapt for DOS version!) Win_Clear Message("\n\n Sorry, but this macro requires the Windows version of VEDIT.") return } // here you have to tell the language of your Windows (I don't know a secure way of determining it automatically here) // #91=1 // 0=english, 1=german // for testing only! // #90=1 // if(#90==1){ // #91=0 // } Key_Add(`Shft-F1`, `[VISUAL EXIT] CALL(100, "HELP") `, OK) Key_Add(`F11`, `[VISUAL EXIT] CALL(100, "SORTMENU") `, OK) Key_Add(`Shft-F11`, `[VISUAL EXIT] #93=0 CALL(100, "SORTFILE") `, OK) Key_Add(`Ctrl-F11`, `[VISUAL EXIT] #93=0 CALL(100, "SORTPATH") `, OK) Key_Add(`Alt-F11`, `[VISUAL EXIT] #93=0 CALL(100, "SORTDATE") `, OK) Key_Add(`Ctrl-Shft-F11`, `[VISUAL EXIT] #93=0 CALL(100, "SORTSIZE") `, OK) Key_Add(`F12`, `[VISUAL EXIT] CALL(100, "LOADFILE") `, OK) Key_Add(`Shft-F12`, `[VISUAL EXIT] CALL(100, "COMPAREFILES") `, OK) Key_Add(`Ctrl-F12`, `[VISUAL EXIT] CALL(100, "DELETEFILE") `, OK) Key_Add(`Alt-F12`, `[VISUAL EXIT] CALL(100, "GETDIR") `, OK) Call("GETDIR") // load new DIR-File return //========================================================================================= // Show some help instructions :HELP: if(Buf_Num==#92){ Win_Clear Message(` *** XTREE.VDM - Poor man's file manager *** Shft-F1 Show this help F11 Menu for sorting the file (or use the keys below directly) Shft-F11 Sort the list by filename Ctrl-F11 Sort the list by pathname Alt-F11 Sort the list by date/time Ctrl-Shft-F11 Sort the list by size F12 Load the file the cursor is on into VEDIT (and close it again) Shft-F12 Compare the two files (cursor on first one) Ctrl-F12 Delete file -or- all files marked as block (caution!) Alt-F12 Re-read the directory contents and thus rebuild the list `) Visual_Macro(NOMSG) Get_Key("\nPress any key to close help...", STATLINE+RAW) } return //---------------------------------------------- :SORTMENU: #103=1 // Ascending as default #104=Dialog_Input_1(103,"`Sort menu`, `Please choose a sorting method:`, `.g()ascending`, `()descending`, ` and sort the file by `, `.b[&Filename]`,`[&Pathname]`,`[&Date]`,`[&Size]`, `.v[&Cancel]`",SET+APP+CENTER,0,0) if((#104==5) || (#104==0)){ return } #93 = #103-1 // sorting order: 0 = asc, 1 = desc if(#104==1){ Call("SORTFILE") } if(#104==2){ Call("SORTPATH") } if(#104==3){ Call("SORTDATE") } if(#104==4){ Call("SORTSIZE") } return //---------------------------------------------- :SORTFILE: // sort the files by filename and path BoF Browse_Mode(CLEAR) Search("||", COUNT, 2) #103 = Cur_Col Num_Str(#103, 103, LEFT+NOCR) Reg_Set(103, "1:", INSERT) File_Save(NOMSG) // workaround // BUG: doesn't work! "NOT ENOUGH MEMORY ...:" if(#93){ Sort_Merge(@(103), 0, File_Size, REVERSE) }else{ Sort_Merge(@(103), 0, File_Size) } File_Save(NOMSG) // workaround BoF Browse_Mode(SET) return // ----------------------------- :SORTPATH: // sort the files by path BoF Browse_Mode(CLEAR) Search("||") #103 = Cur_Col + 1 Search("||", COUNT, 2) Num_Str(#103, 103, LEFT+NOCR) Reg_Set(103, ":", APPEND) Num_Str(Cur_Col, 103, LEFT+NOCR+APPEND) // workaround: File_Save befor Sort_Merge File_Save(NOMSG) if(#93){ Sort_Merge(@(103), 0, File_Size, REVERSE) }else{ Sort_Merge(@(103), 0, File_Size) } File_Save(NOMSG) // workaround BoF Browse_Mode(SET) return // ----------------------------- :SORTDATE: // sort the file by date and time // Attention: for german format only yet! dd.mm.yyyy hh:mmm BoF Browse_Mode(CLEAR) Search("||", COUNT, 2) Char(2) // begin of date (= day in german and month in english date format) #103 = Cur_Col Search(" ") // end of date #104 = Cur_Col #105 = #104 Search("|!|D", REVERSE+ADVANCE) // begin of year Num_Str(Cur_Col, 106, LEFT+NOCR) Reg_Set(106, ":", APPEND) Num_Str(#104, 106, LEFT+NOCR+APPEND) Reg_Set(106, ",", APPEND) if(#91==0){ // english Goto_Col(#103) Num_Str(Cur_Col, 106, LEFT+NOCR+APPEND) // month Reg_Set(106, ":", APPEND) Search("|!|D", COUNT, 2) // end of day Num_Str(Cur_Col-1, 106, LEFT+NOCR+APPEND) Reg_Set(106, ",", APPEND) }else{ if(#91==1){ // german Char(-1) // end of month #104 = Cur_Col Search("|!|D", REVERSE+ADVANCE) // begin of month Num_Str(Cur_Col, 106, LEFT+NOCR+APPEND) Reg_Set(106, ":", APPEND) Num_Str(#104, 106, LEFT+NOCR+APPEND) Reg_Set(106, ",", APPEND) Num_Str(#103, 106, LEFT+NOCR+APPEND) // day Reg_Set(106, ":", APPEND) Num_Str(Cur_Col-1, 106, LEFT+NOCR+APPEND) Reg_Set(106, ",", APPEND) }else{ // yet undefined language BoF Browse_Mode(SET) return } } Goto_Col(#105) Num_Str(#105, 106, LEFT+NOCR+APPEND) // time Reg_Set(106, ":", APPEND) Search("|!|W") Search("|W") Num_Str(Cur_Col, 106, LEFT+NOCR+APPEND) // workaround: File_Save befor Sort_Merge File_Save(NOMSG) if(#93){ Sort_Merge(@(106), 0, File_Size, REVERSE) }else{ Sort_Merge(@(106), 0, File_Size) } File_Save(NOMSG) // workaround BoF Browse_Mode(SET) return //-#-##-#-#-#- if the Num_Str()-bug is fixed it should work this way too: BoF Browse_Mode(CLEAR) Search("||", COUNT, 2) Char(2) // begin of date (= day) #103 = Cur_Col Search("|!|D") // end of day => begin of month Num_Str(#103, 106, LEFT+NOCR) Reg_Set(106, ":", APPEND) Num_Str(Cur_Col, 106, LEFT+NOCR+APPEND) Reg_Set(106, ",", APPEND) rt(106) Char(1) // begin of month #103 = Cur_Col Search("|!|D") // end of month => begin of year Reg_Set(106, ",", INSERT) rt(106) Num_Str(Cur_Col, 106, LEFT+NOCR+INSERT) rt(106) Reg_Set(106, ":", INSERT) rt(106) Num_Str(#103, 106, LEFT+NOCR+INSERT) rt(106) Char(1) // begin of year #103 = Cur_Col Search("|W") // end of year Reg_Set(106, ",", INSERT) Num_Str(Cur_Col, 106, LEFT+NOCR+INSERT) Reg_Set(106, ":", INSERT) Num_Str(#103, 106, LEFT+NOCR+INSERT) rt(106) Num_Str(Cur_Col, 106, LEFT+NOCR+APPEND) // time Reg_Set(106, ":", APPEND) Search("|!|W") Search("|W") Num_Str(Cur_Col, 106, LEFT+NOCR+APPEND) rt(106) // BUG: Sort_Merge doesn't work! "NOT ENOUGH MEMORY ...:" // workaround: File_Save befor Sort_Merge File_Save(NOMSG) Sort_Merge(@(106), 0, File_Size) // Sort(0, File_Size) File_Save(NOMSG) // workaround BoF Browse_Mode(SET) return // ----------------------------- :SORTSIZE: // sort the files by size BoF Browse_Mode(CLEAR) Search("||", COUNT, 2) // column begin of date,time,size Char(1) Search("|!|W") // date Search("|W") Search("|!|W") // time Search("|W") // end of time Num_Str(Cur_Col, 103, LEFT+NOCR) Reg_Set(103, ":", APPEND) Search("|!|W") // begin of this size entry Search("|X") // end of size Num_Str(Cur_Col, 103, LEFT+NOCR+APPEND) // workaround: File_Save befor Sort_Merge File_Save(NOMSG) if(#93){ Sort_Merge(@(103), 0, File_Size, REVERSE) }else{ Sort_Merge(@(103), 0, File_Size) } File_Save(NOMSG) // workaround BoF Browse_Mode(SET) return // ----------------------------- :GETDIR: // if(Buf_Status != -1){ ???? Chdir(PATH_ONLY) // if a file is open: change to it's directory // } Visual_Macro(NOMSG) #104=1 #103=Dialog_Input_1(104,"`XTREE`, `Please choose a directory in the following dialog box \nby 'opening' a file in the desired directory; \nor [Cancel].`, `[] recursive (with subdirectories)`, `[&Ok]`,`[&Cancel]`", APP+CENTER,0,0) if((#103==0) || (#103==2)){ return } #103=Buf_Num if(Get_Filename(103,"|(CUR_DIR)\*.*")==0){ // bug? pfad wird nicht immer beachtet!?!?! // manuelle Eingabe wenn verzeichnis leer?! return // o.k.??? } Buf_Switch(Buf_Free(EXTRA)) Reg_Ins(103) Search("\",REVERSE+NOERR) Reg_Copy_Block(104, 2, Cur_Pos) // fixes from 1, Buf_Quit(OK) Chdir(@104) #103=File_Check("|(VEDIT_TEMP)\XTREE.DIR") if(#103 != -1){ Buf_Switch(#103) Buf_Quit(OK) } Buf_Switch(#92=Buf_Free) // // for debugging! // if(#90){ // File_Save_As("|(VEDIT_TEMP)\XTREE.DIR", OK) // Ins_File("d:\xxx\DIR-EN.txt") // }else{ if(#104){ System("DIR /S |@(104) > |(VEDIT_TEMP)\XTREE.DIR", DOS+SIMPLE+NOMSG) }else{ System("DIR |@(104) > |(VEDIT_TEMP)\XTREE.DIR", DOS+SIMPLE+NOMSG) } File_Open("|(VEDIT_TEMP)\XTREE.DIR") //} // Delete several unneeded lines // english Windows if(#91==0){ R("|<|*Volume in |*|N", BEGIN+ALL+CASE+NOERR) if(EM){ return } R("|<|* Volume Serial Number |*|N", BEGIN+ALL+CASE+NOERR) R("|<|* file(s) |*|N", "", BEGIN+ALL+CASE+NOERR) R("|<|* dir(s) |*|N", BEGIN+ALL+CASE+NOERR) R("||*|N", "", BEGIN+ALL+CASE+NOERR) R("|<|X", "", BEGIN+ALL+NOERR) }else{ // german Windows R("|<|*Datentr„ger in|*|N", BEGIN+ALL+NOERR) if(EM){ return } R("|<|* Datentr„gernummer|*|N", BEGIN+ALL+CASE+NOERR) R("|<|* Datei(en)|*|N", "", BEGIN+ALL+CASE+NOERR) R("|<|* Verzeichnis(se)|*|N", BEGIN+ALL+CASE+NOERR) R("|<|* Anzahl der |*|N", "", BEGIN+ALL+CASE+NOERR) R("|<|*|*|N", "", BEGIN+ALL+CASE+NOERR) R("|<|X", "", BEGIN+ALL+NOERR) } // resort every line to have the filename leading if(#91==0){ Reg_Set(103,"Directory of ") }else{ Reg_Set(103,"Verzeichnis von ") } // if(Is_WinNT && (#90==0)){ // WinNT/2000/XP if(Is_WinNT){ // WinNT/2000/XP BoF While(! At_EOF){ S("|<|@(103)", ADVANCE+NOERR) RCB(11, CP, EOL_POS) // path BoL Del_Line(1) Set_Marker(6, CP) While(Match("|@(103)")!=0){ if(At_EoF) { break } BoL RCB(12, CP, CP+39) // date, time, size RCB(13, CP+39, EOL_Pos) // name BoL Del_Line(1) RI(13) IT(" | ") RI(11) IT(" | ") RI(12) IN(1) } } }else{ // Win95/98/ME BoF While(! At_EOF){ S("|<|@(103)", ADVANCE+NOERR) RCB(11, CP, EOL_POS) // path BoL Del_Line(1) Set_Marker(6, CP) While(Match("|<|@(103)")!=0){ if(At_EoF) { break } BoL RCB(12, CP+28, CP+44) // date, time RCB(12, CP+13, CP+27, APPEND) // size RCB(13, CP+44, EOL_Pos) // name BoL Del_Line(1) RI(13) IT(" | ") RI(11) IT(" | ") RI(12) IN(1) } } } // beautify (line up) the path BoF #103=0 while(! At_EoF){ S("||", NOERR+ERRBREAK) if(Cur_Col > #103){ #103 = Cur_Col } Line(1, NOERR) } BoF while(! At_EoF){ S("||", NOERR+ERRBREAK) Ins_Indent(#103) Line(1, NOERR) } #97 = #103 // remember the pos of the 1st | // beautify (line up) the date and size BoF #103=0 while(! At_EoF){ S("||", NOERR+ERRBREAK+COUNT, 2) if(Cur_Col > #103){ #103 = Cur_Col } Line(1, NOERR) } BoF while(! At_EoF){ S("||", NOERR+ERRBREAK+COUNT, 2) Ins_Indent(#103) Line(1, NOERR) } #98 = #103 // remember the pos of the 2nd | BoF File_Save(NOMSG) Browse_Mode(SET) return //========================================================================================= // Load the file where the cursor is on :LOADFILE: if(Buf_Num==#92){ BoL Search("|{||,|N}", NOERR) if(EM){ return } #103=Cur_Pos Char(1) Search("|!|W") #104=Cur_Pos Search("|{||,|N}", NOERR) Search("|! ", REVERSE+ADVANCE) Reg_Copy_Block(103, Cur_Pos, #104) Reg_Set(103, "\", APPEND) Goto_Pos(#103) Search("|! ", REVERSE+ADVANCE) Reg_Copy_Block(103, BoL_Pos, Cur_Pos, APPEND) BoL File_Open("|@(103)") #96=Buf_Num+1000 }else{ if(Buf_Num == (#96-1000)){ File_Close(CONFIRM+NOMSG) Buf_Quit() Buf_Switch(#92) } } return //========================================================================================= // Compare two files :COMPAREFILES: if(Buf_Num==#92){ // 1st file BoL Search("|{||,|N}", NOERR) if(EM){ return } #103=Cur_Pos Char(1) Search("|!|W") #104=Cur_Pos Search("|{||,|N}", NOERR) Search("|! ", REVERSE+ADVANCE) Reg_Copy_Block(103, Cur_Pos, #104) Reg_Set(103, "\", APPEND) Goto_Pos(#103) Search("|! ", REVERSE+ADVANCE) Reg_Copy_Block(103, BoL_Pos, Cur_Pos, APPEND) Line(1) // 2nd file BoL Search("|{||,|N}", NOERR) if(EM){ return } #103=Cur_Pos Char(1) Search("|!|W") #104=Cur_Pos Search("|{||,|N}", NOERR) Search("|! ", REVERSE+ADVANCE) Reg_Copy_Block(104, Cur_Pos, #104) Reg_Set(104, "\", APPEND) Goto_Pos(#103) Search("|! ", REVERSE+ADVANCE) Reg_Copy_Block(104, BoL_Pos, Cur_Pos, APPEND) Line(-1) // cursor again on 1st file // // Workaround for the limitations of the command line // Out_Reg(105) if (OS_TYPE==1) { Message('Win_Move(APP, ') //move the new VEDIT some pixels down and right Num_Type(App_X_Org+20, LEFT+NOCR) //to make it obvious that it's a second instance Message(', ') Num_Type(App_Y_Org+20, LEFT+NOCR) Message(', APPW, APPH) ') } Message('File_Open("') //Open the two files to compare Reg_Type(103) Message('") File_Open("') Reg_Type(104) Message('") Buf_Switch(1) ') Message('N_Option(1) Chain_File(100,"compare.vdm")') //Call the compare macro with disabled input dialog Out_Reg(CLEAR) Reg_Save(105,"|(HOME)\CMPDIR$.VDM", OK) Sys("|(VEDIT_EXE) -x |(HOME)\CMPDIR$.VDM ",NOWAIT+NOMSG) } return //========================================================================================= // Delete file(s) and line(s) :DELETEFILE: if(Buf_Num==#92){ Browse_Mode(CLEAR) BoL #106=1 Reg_Set(106, "file") Reg_Copy_Block(105, Cur_Pos, Cur_Pos + #97-1) if((BB != -1) && (BE != -1)){ Goto_Pos(Max(BB,BE)) if(At_BoL){ Line(-1) EoL } #106=Cur_Line #105=Cur_Pos #104=Cur_Pos Goto_Pos(Min(BB,BE)) #106 = #106 - Cur_Line + 1 Num_Str(#106, 106, LEFT+NOCR) if(#106 <= 5){ Reg_Set(106, " files of the marked block:", APPEND) Reg_Copy_Block(105, Cur_Pos, #105, COLSET, 1, #97-1) }else{ Reg_Set(106, " files of the marked block, from/to", APPEND) #105=Cur_Pos Line(1) Reg_Copy_Block(105, #105, Cur_Pos, COLSET, 1, #97-1) Out_Reg(105, APPEND) Message("[...]\n") Out_Reg(CLEAR) Goto_Pos(#104) // last marked line Line(-1) Reg_Copy_Block(105, Cur_Pos, #104, COLSET+APPEND, 1, #97-1) Goto_Pos(#105) // BB } } #104=Dialog_Input_1(104,"`XTREE`, `Do you really want to delete the |@(106) ?`, `|@(105)`, `[&No]`,`[&Yes]`,`[Cancel]`", APP+CENTER,0,0) if(#104 == 2){ // if really delete Reg_Empty(103) for(#105=1 ; #105 <= #106 ; #105++){ BoL Search("|{||,|N}", NOERR) if(EM){ return } #103=Cur_Pos // 1.st | Char(1) Search("|!|W") // begin of path #104=Cur_Pos Search("|{||,|N}", NOERR) Search("|! ", REVERSE+ADVANCE) // end of path Reg_Copy_Block(103, Cur_Pos, #104) // path Reg_Set(103, "\", APPEND) Goto_Pos(#103) Search("|! ", REVERSE+ADVANCE) // end of filename Reg_Copy_Block(103, BoL_Pos, Cur_Pos, APPEND) // filename if(File_Delete("|@(103)", OK) > 0){ BoL Del_Line(1) }else{ Line(1, NOERR) } } } Browse_Mode(SET) } return //===================================================================================