// FINDFILE.VDM - Find a file. // - Finds all files that match the specified search criteria: filename, date, size etc. // - Default directory is current files directory // - Creates an .ini file to control operation of Wildfilew.vdm // - Creates a macro to check if a file matches any additional search criteria, // and then uses Wildfilew.vdm to execute this macro with all the files that match the filter. // // 2007-05-16 v0.1 by Pauli Lindgren // 2009-11-24 v1.0 // 2010-10-31 v1.1 - Show number of files that match options (#22) // 2011-01-11 v1.2 - Check if directory exists. // 2011-06-06 v1.3 - Use cur_dir if no saved path found. Allow spaces in filenames. // // Global numregs, not changed by Wildfilew.vdm: // #20 = T-Reg for wildifew.vdm // #21 = number of files found // #22 = Number of files that match options (size, date etc.) // // Internal numregs, pushed and restored before calling Winldfile: // #80 = Search subdirectories checkbox // #81 = List file size and date checkbox // #82 = File Date radio buttons: 1=no check, 2=newer, 3=older // #83 = File Size radio buttons: 1=no check, 2=smaller, 3=larger // #84 = Read-only checkbox (0x01) + Read-Write checkbox (0x02) // #85 = Flag: open file directly if only 1 match found // #89 = tmp for calculations // // #91 = T-reg for filename // #92 = T-Reg for default path // #93 = T-Reg for date // #94 = T-Reg for file size :RESTART: Num_Push(#80,#94) // Ensure T-Regs #91,#92, #93 and #94 are adjacent (for dialog box) #91 = Reg_Free // #91 = T-Reg for filename while (Reg_Size(#91) || Reg_Size(#91+1) || Reg_Size(#91+2) || Reg_Size(#91+3)) { #91++ } #92=#91+1 // #92 = T-Reg for default path #93=#91+2 // #93 = T-Reg for date #94=#91+3 // #94 = T-Reg for file size // Set default values: Reg_Empty(#92) // Use stored path if no files open Reg_Set(103, FILENAME) if (Reg_Size(103)) { if (Reg_Compare(103, "search.tmp") != 0) { // do not use the path of search.tmp Reg_Set(#92, PATH_ONLY) // Default directory on current files directory } } #22 = 0 // number of files that match options (size, date etc.) #80 = 1 // flag: search subdirectories #81 = 0 // flag: list file details #85 = 1 // Flag: open file directly if only 1 match found Call("READ_SETTINGS") // Read previous settings if (Reg_Size(#92) == 0) { // no saved path found RS(#92, CUR_DIR) // use current dir } Num_Push(#91,#91+6) // save numregs that are modified by dialog box [[ #100=#91 #@100 = #80; #100++ // Checkbox: subdirectorires #@100 = #81; #100++ // Checkbox: List file details #@100 = #85; #100++ // Checkbox: Open file directly if only 1 match found #@100 = 1; #100++ // Radio: do not check file data #@100 = 1; #100++ // Radio: do not check file size #@100 = 1; #100++ // Checkbox: Read-only files #@100 = 1; #100++ // Checkbox: Read/Write files #@100 = 0; #100++ // Checkbox: Hidden files #43 = 1 // simple dialog :MAIN_DIALOG: if (#43==2) { // full dialog box Reg_Set(103," `Advanced options:`, `.l.g()Do no&t check file date`, `()Only files &newer than...`, `()Only files &older than...`, `?? &Modified during last n days: `, `.l.g()Do not check file si&ze`, `()Only files &smaller than...`, `()Only files l&arger than...`, `?? &Size in bytes: `, `[]&Read-only files`, `.h[]Read/&Write files `, `[]&Hidden and system files`, `.v.l.b[Ok]`,`.h.l[Cancel]`,`.l[ Less options << ]`, ") } else { // simple dialog box Reg_Set(103," `.v.l.b[Ok]`,`.h.l[Cancel]`,`.l[ &Advanced >> ]`, ") } #89 = DI1(#91,^`Find File`, `Enter list of filenames to find, separated by commas.\t The wildcards "?" and "*" may be used.`, `??&Files: `, `??&Directory:`, `[]Search s&ubdirectories`,`.h.r[&Browse]`, `[]&List file details (size, date, attrib)`, `[]&Open file directly if only 1 match found `, |@(103)^, APP+CENTER+TOP+SET,0,140) if ( #89 == 0 || #89 == 3 ) { // [Cancel] or . Num_Pop(#91,#91+6) // ] Goto CANCEL } if ( #89 == 1 ) { // [Browse] Reg_Set(103,@(#92)) Reg_Set(103,"\Select directory",APPEND) File_Exist(@103,NOERR) if (Error_Flag == 3) { // if directory not found Reg_Set(103,"\Select directory") // start from root directory } if (Get_Filename(103,"*.*","Change directory",SET)) { // remove filename from path Buf_Switch(XBUF1) Buf_Empty(OK) Reg_Ins(103) EOF if (Search("\",REVERSE+NOERR)) { Del_Block(CP,EOB_pos) } BOF Reg_Copy_Block(#92,Cur_Pos,EOL_pos) Buf_Quit(OK) } goto MAIN_DIALOG } if ( #89 == 4 ) { // [Advanced >>] / [Less <<] if (#43==1) { #43 = 2 } else { #43 = 1 } goto MAIN_DIALOG } #100 = #91 #80 = #@100 #100++ // Search subdirectories checkbox #81 = #@100 #100++ // List file date and time checkbox #85 = #@100 #100++ // Open file directly checkbox #82 = #@100 #100++ // File Date radio buttons #83 = #@100 #100++ // File Size radio buttons #84 = #@100 #100++ // Read-only checkbox if (#@100) { #84 = #84 | 2 } // Read/write checkbox if (#84==0) { #84 = 3} // if nether checked, check both #100++ if (#@100) { #84 = #84 | 4 } // Hidden and System files checkbox if (#43 < 2) { // not full dialog #82 = 1 // do not check file date #83 = 1 // do not checl file size #84 = 3 // do not check read-only attribute, do not show hidden files } // Check input values: if (#82 > 1) { // File date to be checked if (Num_Eval_Reg(#93,SUPPRESS) < 1) { Alert() Statline_Message("Invalid number of days") goto MAIN_DIALOG } } if (#83 > 1) { // File size to be checked if (Num_Eval_Reg(#94,SUPPRESS) < 1) { Alert() Statline_Message("Invalid file size") goto MAIN_DIALOG } } File_Exist("|@(#92)\*.*",NOERR) if (Error_Flag == 3) { // if directory not found Alert() DI1(0,"`FindFile - Directory not found`, `Directory not found:\t\t\t\t`, `.\|@(#92)`", APP+CENTER+TOP,0,170) goto MAIN_DIALOG } Num_Pop(#91,#91+6) // ] ////////////////////////////////////////////////////////////////////////// // // // Create a macro for checking if file matches selected options // // // ////////////////////////////////////////////////////////////////////////// Statline_Message("Creating macro") File_Open("|(VEDIT_TEMP)\ff.vdm",OVERWRITE+NOMSG+NOEVENT) BOF Del_Char(ALL) Ins_Text(^// This macro was created by FindFile.vdm Reg_Set(#51=Reg_Free,PATHNAME) // T-Reg for current file's full pathname #30 = File_Size #31 = File_Stamp_Date() #32 = File_Attrib(PATHNAME) #87 = Buf_Num Buf_Switch(#61) // Use search.tmp for test results if ((#98 & 1) == 0) { // first call from Wildfile? #98 |= 1 // first call done BOF Del_Char(ALL) // erase old contents of search.tmp } ^) if ((#84 & 2) == 0) { // do not show R/W files Ins_Text(^ if ((#32 & 1) == 0) { Goto END_OF_TEST } ^) } if ((#84 & 1) == 0) { // do not show Read-only files Ins_Text(^ if (#32 & 1) { Goto END_OF_TEST } ^) } if ((#84 & 4) == 0) { // do not show hidden and system files Ins_Text(^ if (#32 & 6) { Goto END_OF_TEST } ^) } if (#82 > 1) { // File date to be checked // Check file date #89 = JDate // #89 = Today's date as Julian number IN Ins_Text(^ if (#31 ^) if (#82==2) { IT("< ") } else { IT("> ") } Num_Ins(#89-Num_Eval_Reg(#93,SUPPRESS),LEFT+NOCR) Ins_Text(") { Goto END_OF_TEST }") IN } if (#83 > 1) { // File size to be checked IN Ins_Text(^ if (#30 ^) if (#83==3) { IT("< ") } else { IT("> ") } Num_Ins(Num_Eval_Reg(#94,SUPPRESS),LEFT+NOCR) Ins_Text(") { Goto END_OF_TEST }") IN } Ins_Text(^ Reg_Ins(#51) IN // write filename #22++ ^) if (#81) { // List file size and date Ins_Text(^ IC(9) Num_Ins(#30,FORCE+NOCR) // list file size IC(9) Num_Ins_Date(#31,NOCR) // list file date IC(9) if (#32 & 1) { IC('R') } else { IC('-') } if (#32 & 2) { IC('H') } else { IC('-') } if (#32 & 4) { IC('S') } else { IC('-') } if (#32 & 32) { IC('A') } else { IC('-') } IN ^) } IT(" Update() :END_OF_TEST: ") Ins_Text(^ if (#98 & 2) { // last call from Wildfile? #98 = 0x17 // Wildfile: keep search.tmp open, no end dialog } Reg_Empty(#51) Buf_Switch(#87) ^) Buf_Close(NOMSG+NOEVENT) ////////////////////////////////////////////////////////////////////////// // // // Create .ini file for Wildfilew.vdm // // // ////////////////////////////////////////////////////////////////////////// Statline_Message("Creating ini file") File_Open("|(VEDIT_TEMP)\ff.ini",OVERWRITE+NOMSG+NOEVENT) BOF Del_Char(ALL) Ins_Text(^// This file was generated by FindFile.vdm opt_startup=0 // batch mode (no dialog) opt_dialog=0 opt_path=3 operation='M' files=^) Reg_Ins(#91) // name of file to find IN Ins_Text("path=") Reg_Ins(#92) // base directory IN Ins_Text("subdir=") // search subdirectories checkbox Num_Ins(#80, LEFT) Ins_Text("ff_details=") // checkbox: list details (for FindFile.vdm only) Num_Ins(#81, LEFT) Ins_Text("open_directly=") // checkbox: Open file directly if only 1 match found (for FindFile.vdm only) Num_Ins(#85, LEFT) Ins_Text(^ display_as=2 macro=|(VEDIT_TEMP)\ff.vdm read-only=1 more=0 ^) Buf_Close(NOMSG+NOEVENT) ////////////////////////////////////////////////////////////////////////// :DONE: Reg_Empty(#91) Reg_Empty(#92) Reg_Empty(#93) Reg_Empty(#94) Num_Pop(#80,#94) // // Call Wildfile, use ff.ini file // #20 = REG_FREE Statline_Message("Calling Wildfile") // debug RS(40,"|(VEDIT_TEMP)\ff.ini") Call_File(#20, "wildfilew.vdm", "read_ini") #21 = Return_Value // number of files found if (#21 == 0) // no files found { Goto RESTART } Num_Str(#21, #20, LEFT) RS(#20, " files found", APPEND) if (#22 != #21) { RS(#20, ", ", APPEND) Num_Str(#22, #20, LEFT+APPEND) RS(#20, " match.", APPEND) } Statline_Message(@(#20)) if (#85) { // flag: Open file directly if only 1 match found if (#21==1) { // just one file matches BOF RCB(#20, CP, EOL_pos) Buf_Quit(OK+DELETE) // close search.tmp File_Open('"|@(#20)"', ATTACH+MRU) // open the file found } } Reg_Empty(#20) Return :CANCEL: Reg_Empty(#91) Reg_Empty(#92) Reg_Empty(#93) Reg_Empty(#94) Num_Pop(#80,#94) Return ////////////////////////////////////////////////////////////////////////// // // // Read previous settings // // // ////////////////////////////////////////////////////////////////////////// :READ_SETTINGS: if (File_Exist("|(VEDIT_TEMP)\ff.ini")) { File_Open("|(VEDIT_TEMP)\ff.ini",OVERWRITE+NOMSG+NOEVENT) if (Search("|