          editor="notepad.exe"    ;Default editor
          ; Common menu for all file types
          ;First figure out where filemenu.dll is installed via registry lookup
          ErrorMode(@OFF)
          wbdir=RegQueryValue(@REGMACHINE,"SOFTWARE\Wilson WindowWare\WinBatch\CurrentVersion")
          if wbdir==0 
             wbdir=RegQueryValue(@REGMACHINE,"SOFTWARE\Wilson WindowWare\WinBatch Compiler\CurrentVersion")
          endif
          ErrorMode(@CANCEL)
          if wbdir==0 then Display(5,"Error","Registry entries missing.  Re-install WinBatch")
          homedir=strcat(wbdir,"system\")

          ;Next see if WinEdit is lurking about via registry lookup
          ErrorMode(@OFF)
          WinEdit=strcat(RegQueryValue(@REGMACHINE,"SOFTWARE\Wilson WindowWare\WinEdit\CurrentVersion"),"WinEdit.exe")
          ErrorMode(@CANCEL)
          if WinEdit==0    ;No?  Try path
             WinEdit=FileLocate("WINEDIT.EXE")
             if WinEdit=="" then WinEdit=editor
          endif

          inifile=strcat(DirWindows(0),"FileMenu.ini")
          if !FileExist(inifile) then inifile=strcat(homedir,"FileMenu.ini")
          commonmenu="FileMenu for all filetypes.mnw"
          defaultmenu="FileMenu for misc filetypes.mnw"

Two Explorers, side by side ; Your dual window file manager
        a=IntControl(31,0,0,0,0)  ;return list of ids of explorer windows
        c=ItemCount(a,@TAB)
        switch c
           case 0
              run("explorer.exe",strcat("/n,/e,",DirGet()))
              while FindWindow("ExploreWClass")==""    ;wait for it to come up
                Yield
              end while
              ;Fall into case 1

           case 1
              run("explorer.exe",strcat("/n,/e,",DirGet()))
              break
           case c       ; 2 or more
              break
        endswitch
        d=1
        while c<2 && d<500
           a=IntControl(31,0,0,0,0)
           c=ItemCount(a,@TAB)
           d=d+1
        endwhile
        if c<2 then exit
        id1=ItemExtract(1,a,@TAB)
        id2=ItemExtract(2,a,@tab)
        WinPlaceSet(@NORMAL,id2,"500 0 1000 900")
        WinShow(id2)
        Yield
        Yield
        WinPlaceSet(@NORMAL,id1,"0 0 500 900")
        WinShow(id1)
     
Open With ... ; Choose an application to view or edit the selected file.
 
 &Browser (binary file viewer)  ; View any file in binary format.
        file = CurrFilePath()
        If !(FileExist(file)) Then file = ""
        Else If FileExtension(file) == "" Then file = StrCat(file, ".")
        Run("browser.exe", FileNameShort(file))     
 &Notepad  ; Modify small plain text files.
        file = CurrFilePath()
        If !(FileExist(file)) Then file = ""
        Else If FileExtension(file) == "" Then file = StrCat(file, ".")
        Run("notepad.exe", file)
 &MSPaint (bitmap) ; View and Modify bitmaps
         file = CurrFilePath()
         If !(FileExist(file)) Then file = ""
              Else If FileExtension(file) == "" Then file = StrCat(file, ".")
         bmpfile = strlower(FileExtension(file))
         If bmpfile != "bmp"
              Message("Error","Select a bitmap file and try again.")
              Exit
         EndIf          
         rkey=RegOpenKey(@REGMACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths")
         mspaintexe=RegQueryValue(rkey,"MSPAINT.EXE")
         RegCloseKey(rkey)
         Run(mspaintexe,file)
 &Wordpad (text and graphics) ; Modify WORD, RTF, plain text files. Can contain bitmaps, too.
         file = CurrFilePath()
         If !(FileExist(file)) Then file = ""
              Else If FileExtension(file) == "" Then file = StrCat(file, ".")
         rkey=RegOpenKey(@REGMACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths")
         wordpadexe=RegQueryValue(rkey,"WORDPAD.EXE")
         RegCloseKey(rkey)
         Run(wordpadexe,file)
 Win&Edit (text) ; Open file with WinEdit
        f = CurrFilePath()
        If !(FileExist(f)) Then f = ""
        Else If FileExtension(f) == "" Then f = StrCat(f, ".")
        Run(WinEdit, f)

     
File Operations

 File/Folder size    ;Sum sizes of all highlighted files and folders
        
        tot = FileSize(FileItemize(""))
        sub1 = DirItemize("")
        totdir=0
        level=1
        dir1=DirGet()
        
        numdir1 = ItemCount(sub1, @tab)
        index1 = 0
  
        :dsloop
        If index%level% == numdir%level% Then Goto upalevel
        index%level% = index%level% + 1
        DirChange(StrCat(dir%level%, ItemExtract(index%level%, sub%level%, @tab)))
        
        totdir=totdir+1
        tot = tot + FileSize(FileItemize("*.*"))
        level = level + 1
        dir%level% = DirGet()
        sub%level% = DirItemize("*.*")
        numdir%level% = ItemCount(sub%level%, @tab)
        index%level% = 0
        goto dsloop
  
        :upalevel
        drop(dir%level%,sub%level%,index%level%,numdir%level%)
        level=level-1
        if level!=0 then goto dsloop
 
        ; -----------
        ; Termination
        ; -----------
        
        If StrLen(tot) < 9 Then tot = StrCat(StrFill("", 9 - StrLen(tot)), tot)
        tot = StrCat(StrSub(tot,1,3),",",StrSub(tot,4,3),",",StrSub(tot,7,3))
        tot = StrTrim(tot)
        If StrSub(tot, 1, 1) == "," Then tot = StrSub(tot, 2, StrLen(tot) - 1)
        tot = StrTrim(tot)
        If StrSub(tot, 1, 1) == "," Then tot = StrSub(tot, 2, StrLen(tot) - 1)
        tot = StrTrim(tot)
        Message("%totdir% Subdirectories included", "Total size %tot% bytes.")

 Print (with Notepad)   ;Print text-type file with notepad on default printer
        Run("notepad.exe",strcat("/p ",FileCurrPath())
 Associate              ;Associate this type of file with an application
        a=strlower(FileExtension(CurrentFile()))
        b=AskFileName("Associate %a% files with","C:\","Executable Files|*.exe;*.com;*.bat;*.pif|All Files|*.*|","",1)
    
        rkey=RegOpenKey(@REGCLASSES,"")
        ErrorMode(@OFF)
        RegDeleteKey(rkey,".%a%")
        ErrorMode(@CANCEL)
        RegSetValue(rkey, ".%a%", "%a%_auto_file")
        RegSetValue(rkey,"%a%_auto_file\shell\open\command",strcat('"',b,'" "%%1"'))
        AU=StrUpper(a)
        RegSetValue(rkey,"%a%_auto_file","%AU% File")
        RegClosekey(rkey)
 File Attributes        ;View file attributes
        files = FileItemize("")
        numfiles = ItemCount(files,@TAB)
        While numfiles == 1
        file = CurrentFile()
        result = FileAttrGet(file)
        If StrLen(file) > 30
             fileindialog = StrSub(file,1,30)
          
             fileindialog = StrCat(fileindialog," ...")
        Else 
             fileindialog = file
        EndIf
     
        readonly = 2
        archive = 2
        system = 2
        hidden = 2
        If StrSub(result,1,1) == "R" Then readonly = "3"
        If StrSub(result,2,1) == "A" Then archive = "3"
        If StrSub(result,3,1) == "S" Then system = "3"
        If StrSub(result,4,1) == "H" Then hidden = "3"

               FileAttributesFormat=`WWWDLGED,5.0`
               
               FileAttributesCaption=`File Attributes`
               FileAttributesX=7
               FileAttributesY=25
               FileAttributesWidth=199
               FileAttributesHeight=101
               FileAttributesNumControls=17
               
               FileAttributes01=`110,86,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Cancel",0`
               FileAttributes02=`42,18,38,DEFAULT,STATICTEXT,DEFAULT,"Read Only"`
               FileAttributes03=`126,18,36,DEFAULT,STATICTEXT,DEFAULT,"System"`
               FileAttributes04=`84,18,36,DEFAULT,STATICTEXT,DEFAULT,"Archive"`
               FileAttributes05=`168,18,36,DEFAULT,STATICTEXT,DEFAULT,"Hidden"`
               FileAttributes06=`56,86,36,DEFAULT,PUSHBUTTON,DEFAULT,"&OK",1`
               FileAttributes07=`2,54,36,DEFAULT,STATICTEXT,DEFAULT,"On"`
               FileAttributes08=`2,36,36,DEFAULT,STATICTEXT,DEFAULT,"Off"`
               FileAttributes09=`2,4,194,DEFAULT,STATICTEXT,DEFAULT,"Set File Attributes for => %fileindialog% "`
               FileAttributes10=`42,36,36,DEFAULT,RADIOBUTTON,readonly,"",2`
               FileAttributes11=`42,54,36,DEFAULT,RADIOBUTTON,readonly,"",3`
               FileAttributes12=`166,54,36,DEFAULT,RADIOBUTTON,hidden,"",3`
               FileAttributes13=`84,36,36,DEFAULT,RADIOBUTTON,archive,"",2`
               FileAttributes14=`84,54,36,DEFAULT,RADIOBUTTON,archive,"",3`
               FileAttributes15=`166,36,36,DEFAULT,RADIOBUTTON,hidden,"",2`
               FileAttributes16=`126,36,36,DEFAULT,RADIOBUTTON,system,"",2`
               FileAttributes17=`126,54,36,DEFAULT,RADIOBUTTON,system,"",3`
               
               ButtonPushed=Dialog("FileAttributes")



           Select buttonpushed
          
               Case 0
                    Break
                    
               Case 1

                    first = ""
                    second = ""
                    third = ""
                    fourth = ""
                    If readonly == 2 Then first = "r"
                    If archive == 2 Then second = "a"
                    If system == 2 Then third = "s"
                    If hidden == 2 Then fourth = "h"
                    If readonly == 3 Then first = "R"
                    If archive == 3 Then second = "A"
                    If system == 3 Then third = "S"
                    If hidden == 3 Then fourth = "H"

                    
                    
                    
                    attributes = StrCat( first, second, third, fourth )
                    FileAttrSet(file, attributes)
                    break
           End Select
                

     Exit
     EndWhile

     ;Set Attributes: Selected Files

     displayfiles = files
     readonly = 1
     archive = 1
     system = 1
     hidden = 1
               AttribFormat=`WWWDLGED,5.0`
               
               AttribCaption=`Attributes`
               AttribX=6
               AttribY=25
               AttribWidth=201
               AttribHeight=101
               AttribNumControls=22
               
               Attrib01=`110,86,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Cancel",0`
               Attrib02=`42,18,38,DEFAULT,STATICTEXT,DEFAULT,"Read Only"`
               Attrib03=`126,18,36,DEFAULT,STATICTEXT,DEFAULT,"System"`
               Attrib04=`84,18,36,DEFAULT,STATICTEXT,DEFAULT,"Archive"`
               Attrib05=`168,18,36,DEFAULT,STATICTEXT,DEFAULT,"Hidden"`
               Attrib06=`2,34,38,DEFAULT,STATICTEXT,DEFAULT,"No Change"`
               Attrib07=`2,70,36,DEFAULT,STATICTEXT,DEFAULT,"On"`
               Attrib08=`2,52,36,DEFAULT,STATICTEXT,DEFAULT,"Off"`
               Attrib09=`42,34,36,DEFAULT,RADIOBUTTON,readonly,"",1`
               Attrib10=`42,52,36,DEFAULT,RADIOBUTTON,readonly,"",2`
               Attrib11=`42,70,36,DEFAULT,RADIOBUTTON,readonly,"",3`
               Attrib12=`84,34,36,DEFAULT,RADIOBUTTON,archive,"",1`
               Attrib13=`84,52,36,DEFAULT,RADIOBUTTON,archive,"",2`
               Attrib14=`84,70,36,DEFAULT,RADIOBUTTON,archive,"",3`
               Attrib15=`126,34,36,DEFAULT,RADIOBUTTON,system,"",1`
               Attrib16=`126,52,36,DEFAULT,RADIOBUTTON,system,"",2`
               Attrib17=`126,70,36,DEFAULT,RADIOBUTTON,system,"",3`
               Attrib18=`168,34,36,DEFAULT,RADIOBUTTON,hidden,"",1`
               Attrib19=`168,52,36,DEFAULT,RADIOBUTTON,hidden,"",2`
               Attrib20=`168,70,36,DEFAULT,RADIOBUTTON,hidden,"",3`
               Attrib21=`58,2,130,DEFAULT,STATICTEXT,DEFAULT,"Set Attributes for Selected Files"`
               Attrib22=`56,86,36,DEFAULT,PUSHBUTTON,DEFAULT,"&OK",1`
               
               ButtonPushed=Dialog("Attrib")
               



          Select buttonpushed
          
               Case 0
                    Break
                    
               Case 1

                    first = ""
                    second = ""
                    third = ""
                    fourth = ""
                    If readonly == 2 Then first = "r"
                    If archive == 2 Then second = "a"
                    If system == 2 Then third = "s"
                    If hidden == 2 Then fourth = "h"
                    If readonly == 3 Then first = "R"
                    If archive == 3 Then second = "A"
                    If system == 3 Then third = "S"
                    If hidden == 3 Then fourth = "H"

                    
                    
                    
                    attributes = StrCat( first, second, third, fourth )
                    FileAttrSet(files, attributes)
                    break
           End Select
      Exit                              
 

 DOS &Copy  ; Like the good, old, DOS COPY command.
       s = StrTrim(FileItemize(""))
       s=StrReplace(s,@tab,"|")
       If s == "" Then Message("Copy Error", "No files selected")
       Then Exit
       If ItemCount(s, "|") == 1 Then t = s
       Else t = ""
       t = AskLine("Copy", StrCat(s, @CRLF, @CRLF, "to"), t)
       If t == "" Then Message("Copy Error", "Cannot copy to null file name")
               Then Exit
       FileCopy(s, t, @TRUE)

 DOS &Rename  ;Like the good, old DOS RENAME command.
       s = StrTrim(FileItemize(""))
       s=StrReplace(s,@tab,"|")
       If s == "" Then Message("Rename Error", "No files selected")
       Then Exit
       If ItemCount(s, "|") == 1 Then t = s
       Else t = ""
       t = AskLine("Rename", StrCat(s, @CRLF, @CRLF, "to"), t)
       If t == "" Then Message("Rename Error", "Cannot rename to null file name")
                  Then Exit
       FileRename(s, t)

  
Clipboard Tricks ; Copies just the filenames to the clipboard
 FileName(s) to Clipboard ; Just the filenames
        a=FileItemize("")
        a=ItemSort(a,@tab)
        a=strreplace(a,@TAB,@CRLF)
        ClipPut(a)
        Display(2,"Filenames placed on Clipboard",a)
 Path and FileName(s) to Clipboard ; Copies filenames with full paths to the Clipboard
        a=FileItemize("")
        a=ItemSort(a,@TAB)
        a=strcat(@TAB,StrSub(a,1,strlen(a)-1))
        b=DirGet()
        a=StrSub(StrReplace(a,@TAB,strcat(@TAB,b)),2,-1)
        a=StrReplace(a,@TAB,@CRLF)
        ClipPut(a)
        Display(2,"Full path filenames placed on Clipboard",a)
 Path to Clipboard   ; Copies just the path to the clipboard
        a=DirGet()
        ClipPut(a)
        Display(2,"Path placed on Clipboard",a)
        
        
 _Run Clipboard Viewer   ; Lets you see what is on the clipboard
        Run("clipbd.exe","")


WIL Interactive
 Execute a function
        call("%homedir%wwwmenu95.wil","CMDSTACK NEWCMD")
 _Load WIL Help File
        WinHelp(strcat(wbdir,"Windows Interface Language.hlp"),"CONTENTS","")     
      


     
_Edit File Menus ; Modify WinBatch FileMenus here 
 Edit menu for this filetype  ; Edit menus for files with a specific file extension.
        b=strupper(FileExtension(CurrentFile()))
        a=IniReadPvt("Menus",b,"*NONE*",inifile)
        if a=="*NONE*" then a=strcat("FileMenu for %b% files",".mnw")
        if FilePath(a)=="" then a=strcat(HomeDir,a)
        ;Message(a,FileExist(a))
        if !(FileExist(a))
                c=AskYesNo("Please note:","The menu file for the %b% filetype does not exist.  Would you like to start a new one?")
                if c==@NO then exit
                c=               "; WinBatch FileMenu for %b% filetype%@CRLF%"
                c=strcat(c,@CRLF,"; This is a sample menu file to help you get started")
                c=strcat(c,@CRLF,"; writing your very own Winbatch FileMenu menus.  It is")
                c=strcat(c,@CRLF,"; really not too bad.  WinBatch is a simple programming")
                c=strcat(c,@CRLF,"; language.  You can find out just about all you need to")
                c=strcat(c,@CRLF,"; know from the Windows Interface Language help file or")
                c=strcat(c,@CRLF,"; the manual.  Check out the section on Menu Files,")
                c=strcat(c,@CRLF,"; the WIL Tutorial and the WIL Function Reference.")

                c=strcat(c,@CRLF,@CRLF,'Standalone menu item            ; Sample menu item')
                c=strcat(c,@CRLF,      '        Message("Hello","There")')
                c=strcat(c,@CRLF,@CRLF,'Top Level menu item')
                c=strcat(c,@CRLF,      ' Selected File is               ; Shows currently selected file')
                c=strcat(c,@CRLF,      '        a=CurrFilePath()')
                c=strcat(c,@CRLF,      '        Message("Selected File is",a)')
                c=strcat(c,@CRLF,      ' Run Calculator                 ; Sample Run function')
                c=strcat(c,@CRLF,      '        Run("calc.exe","")')
                c=strcat(c,@CRLF,      ' Run Notepad on selected file   ; Sample Run function with filename')
                c=strcat(c,@CRLF,      '        a=CurrFilePath()')
                c=strcat(c,@CRLF,      '        Run("notepad.exe",a)')

                c=strcat(c,@CRLF,@CRLF,'; Note: You may want to delete this menu item if you edit this file')
                c=strcat(c,@CRLF,      ' _Delete this sample menu file  ; Deletes this menu file')

                c=strcat(c,@CRLF,      '        inifile=strcat(DirWindows(0),"FileMenu.ini")')
                c=strcat(c,@CRLF,      '        if !FileExist(inifile) then inifile=strcat(homedir,"FileMenu.ini")')


                c=strcat(c,@CRLF,      '        b=strupper(FileExtension(CurrentFile()))')
                c=strcat(c,@CRLF,      '        a=IniReadPvt("Menus",b,"*NONE*",inifile)')
                c=strcat(c,@CRLF,      '        if a=="*NONE*" then a=strcat("FileMenu for %b% files",".mnw")')
                c=strcat(c,@CRLF,      '        if FilePath(a)=="" then a=strcat(HomeDir,a)')
                c=strcat(c,@CRLF,      '        c=AskYesNo("Are you sure you wish to delete this menu file",a)')
                c=strcat(c,@CRLF,      '        if c==@YES')
                c=strcat(c,@CRLF,      '           IniDeletePvt("Menus",b,inifile)')
                c=strcat(c,@CRLF,      '           FileDelete(a)')
                c=strcat(c,@CRLF,      '        endif')




                c=strcat(c,@CRLF)
                fh=FileOpen(a,"WRITE")
                FileWrite(fh,c)
                FileClose(fh)
                iniwritepvt("Menus",b,a,inifile)
                drop(c)
                
        endif
        Run(Editor,a)
 ;Edit the Miscellaneous File Menu     ; Edit menus for files with unrecognized extensions
 ;       a=IniReadPvt("FileMenu","DefaultMenu",defaultmenu,inifile)
 ;       a=strcat(HomeDir,a)
 ;       Run(Editor,a)
 Edit menu for all filetypes      ; Edit global menu for all files 
        a=IniReadPvt("FileMenu","CommonMenu",commonmenu,inifile)
        a=strcat(HomeDir,a)
        Run(Editor,a) 
 _Load WIL Help File
        WinHelp(strcat(wbdir,"Windows Interface Language.hlp"),"CONTENTS","")     

 _About WinBatch FileMenu  ; Software from Wilson WindowWare
        About()           
           
