forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


String Search in File or Folder...

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code
View previous topic :: View next topic  
Author Message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Thu Jul 18, 2002 1:31 am    Post subject: String Search in File or Folder... Reply with quote

Here's a utility I put together to search for a string in a single
file, or search for the string in all files of a directory (it does
NOT search subdirectories). It shows the name of the file, the
line number(s), and the line(s) the string is found in.
Note: VDS will only load text based files in lists.

It can be run from the command line (with file/dir as parameter)
or as a stand-alone program.

TIP: Compile this program and create a link to it in the
"C:\Windows\SendTo" folder. You can then right click on
a file/folder in Windows Explorer, choose "SendTo", and
choose this program to do a string search on the chosen
file/folder or multiple files (up to 9)...

See the program's "help" for more info.
__________________________________________________________________________________________________________________________
Code:

OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
DIALOG CREATE,String Search,-1,0,600,320,DRAGDROP
  DIALOG ADD,STYLE,Style1,MS San Serif,9,B
  DIALOG ADD,MENU,&Options,Search &File(s)|Ctrl+F,Search &Dir|Ctrl+D,&Save Results As|Ctrl+S,-,E&xit|Alt+X
  DIALOG ADD,MENU,&Help,Help
  DIALOG ADD,LIST,L1,0,0,600,284
  DIALOG ADD,TEXT,T1,285,2,,,"",,Style1
  DIALOG ADD,STATUS,Stat
DIALOG SHOW

LIST CREATE, 1
LIST CREATE, 2, Sorted

rem -- Add horizontal scroll to list --
%z = @sendmsg(@winexists(~L1),$0194,2000,0)

rem -- Check for command line, and if file(s) or directory --
if %1
  if %2
     rem -- Check for multiple folders --
     if @both(@file(%1,D), @file(%2,D))
        WARN Cannot search multiple folders...@tab()
        EXIT
     end
     rem -- If two files found , assume multiple files --
     if @both(@file(%1), @file(%2))
        LIST ADD, 2, %1
        LIST ADD, 2, %2
        LIST ADD, 2, %3
        LIST ADD, 2, %4
        LIST ADD, 2, %5
        LIST ADD, 2, %6
        LIST ADD, 2, %7
        LIST ADD, 2, %8
        LIST ADD, 2, %9
        if %9
           if @not(@ask("Nine (9) files max from command line."@tab()@cr()@cr()"Continue?"))
              EXIT
           end
        end
        goto Search
     end
  end
  %%source = @trim(%1 %2 %3 %4 %5 %6 %7 %8 %9)
  if @file(%%source, D)
     LIST FILELIST, 2, %%source\*.*
     LIST ASSIGN, L1, %%source
     goto Search2
  end
  if @file(%%source)
     LIST ASSIGN, 2, %%source
     goto Search
  end
  WARN "ERROR - File/Dir does not exist..."@cr()%%source@tab()
end

:EVLOOP
  %e = ""
  LIST CLEAR, 1
  LIST CLEAR, 2
  WAIT EVENT
  goto @event()

:HelpMenu
  %h = "You can search for a string in a single file, a folder, or"
  %h = %h" drag 'n drop selected files to search. Displays filename,"
  %h = %h" line number(s), and the line(s) the string is found in."
  %h = %h@cr()@cr()"Program will NOT search subdirs, or multiple folders."
  %h = %h@cr()@cr()"TIP: Create a link to this program in the Windows\SendTo"
  %h = %h" folder. You can then right click on a file/folder in Windows"
  %h = %h" Explorer, choose "SendTo", then choose this program to do a
  %h = %h" string search on the chosen folder/file or multiple files."
  %h = %h@cr()@cr()"If using from Windows Explorer, you may select a max"
  %h = %h" of 9 files (only 9 command line vars available in VDS)."
  %h = %h" You will receive a warning if there is more than 9.
  %h = %h@cr()@cr()"There is NO limit on number of drag 'n dropped files,"
  %h = %h" or multiple selected files from the program itself."
  %h = %h@cr()@cr()"VDS only loads text based files in lists."
  INFO %h
  %h = ""
  goto EVLOOP

:Search File(s)MENU
  %%source = @filedlg("All Files|*.*",,,MULTI)
  if @not(%%source)
     goto EVLOOP
  end
  LIST ASSIGN, 2, %%source
  goto Search

:Search DirMENU
  %%source = @dirdlg()
  if @not(@file(%%source,D))
     goto EVLOOP
  end
  LIST FILELIST, 2, %%source\*.*
  LIST ASSIGN, L1, %%source
  goto Search2

:DragDrop
  LIST DROPFILES, 2
  if @greater(1, @count(2))
     goto EVLOOP
  end
  if @file(@item(2, 0), D)
     WARN You cannot drag and drop folders...@tab()
     goto EVLOOP
  end
  goto Search

:Search
  DIALOG CLEAR, T1
  LIST ASSIGN, L1, 2
:Search2
  %%string = @input(Enter search string:)
  if @not(%%string)
     goto EVLOOP
  end
  LIST CLEAR, L1
  DIALOG SET, T1, Searching for @chr(34)%%string@chr(34)
  %x = 0
  REPEAT
    if @file(@item(2, %x))
       LIST LOADFILE, 1, @item(2, %x)
    else
       goto NextItem
    end
    %y = 0
    REPEAT
      if @greater(@pos(%%string, @item(1, %y)), 0)
         LIST ADD, L1, @item(2, %x)" "Line @succ(%y)"  "@item(1, %y)
      end
      DIALOG SET, Stat, Searching @item(2, %x) line %y
      %e = @event()
      %y = @succ(%y)
    UNTIL @equal(%y, @count(1))@greater(%y, @count(1))%e
    :NextItem
    %x = @succ(%x)
  UNTIL @equal(%x, @count(2))@greater(%x, @count(2))%e
  if %e
     DIALOG SET, Stat, Search aborted...
  else
     DIALOG SET, Stat, Search complete. @count(L1) matches found.
  end
  goto EVLOOP

:Save Results AsMENU
  %%file = @filedlg(,,,SAVE)
  if %%file
     LIST SAVEFILE, L1, %%file
     WAIT
     if @file(%%file)
        INFO File saved as:@cr()@cr()%%file@tab()
     else
        WARN ERROR - File NOT saved...@tab()
     end
  end
  goto EVLOOP

:CLOSE
  EXIT


Cheers, Mac

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361


Last edited by Mac on Thu Jul 18, 2002 8:29 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Thu Jul 18, 2002 8:25 pm    Post subject: Reply with quote

Just finished a major re-write of this program...

- Uses same routine for files, multiple files, and folders.
- Accepts multiple files from Windows Explorer using "SendTo" (up to 9).
- Has file(s) drag and drop capability (no limit).
- Does more error checking.
- Replaced buttons with menus.
- Added "help" info window.

Cheers, Mac Smile

_________________
VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group