Scintilla icon Shell - Lua library for SciTE
Documentation   FAQ   Regular Expressions   Scintilla   LUA   SciTE Director   SciTE and Scintilla Commands   SciTE-Ru Kernel   Shell   SciTE Helper   History  

Description

External Lua library expanding opportunities SciTE Lua Scripting Extension.

DLL loading

Before use of library functions it require load:

package.cpath = props["SciteDefaultHome"].."\\tools\\LuaLib\\?.dll;"..package.cpath
-- show all paths on which SciTE will search for our library
print(package.cpath)
-- library loading
require 'shell'
-- test dll
if shell then
  table.foreach(shell, print)
end

Functions

msgbox (strMessageText, [strTitle], [intOptions])

Description:
  Showing text message with buttons.

Parameters:
  strMessageText - text message
  strTitle - title text of message
  intOptions - numerical expression representing the sum of values, listed in the table.

ValueDescription
0 Display OK button only (default)
1 Display OK and Cancel buttons
2 Display Abort, Retry, and Ignore buttons
3 Display Yes, No, and Cancel buttons
4 Display Yes and No buttons
5 Display Retry and Cancel buttons
16 Display Critical Message icon
32 Display Question Message icon
48 Display Exclamation Message icon
64 Display Information Message icon
0 First button is the default
256 Second button is the default
512 Third button is the default
768 Fourth button is the default
0 Application modal. The user must respond to the message box before continuing work in the current application.
4096 System modal. On Win16 systems, all applications are suspended until the user responds to the message box. On Win32 systems, this constant provides an application modal message box that always remains on top of any other programs you may have running.

Return value:
  Returned code to identify which button a user has selected. Values are listed in the table:

ValueDescription
1 OK button was clicked
2 Cancel button was clicked
3 Abort button was clicked
4 Retry button was clicked
5 Ignore button was clicked
6 Yes button was clicked
7 No button was clicked

Example:

if shell.msgbox("You are sure?", "SciTE", 65) == 1 then
  print("Yes")
end

Authors: Midas, mimir

inputbox(strCaptionText, strPrompt, strDefaultValue, funcCheckInput, intMinWidth)

Description:
  Display dialog box for input some text value.

Parameters:
  strCaptionText - the title for the dialog box. The default is "InputBox".
  strPrompt - the message to be displayed above an edit field. The default is "Enter".
  strDefaultValue - text to be displayed in the edit field. Defaults to "" (the empty string).
  funcCheckInput - the input-checking function. It gets the text from the edit field together with the newly received char and must return either true (to accept this char) or false (to reject it). Default value is nil (it means no restrictions).
  intMinWidth - the minimal width of the edit field in average chars. The default is 20. Note. The dialog box automatically changes its width to accommodate the widest field of the strPrompt and strDefaultValue ones if value proposed by the intMinWidth is not enough.

Return value:
  a string value which is entered by user. nil means that user input was cancelled.

Example:

print(shell.inputbox("Rename", "Enter new file name:", "filename.ext", function(name) return not name:match('[\\/:|*?"<>]') end))

Author: qVaclav

getfileattr (strFileName)

Description:
  Get file attributes.

Parameters:
  strFileName - filename

Return value:
  contains file attributes as number

Example:

local attr = shell.getfileattr("c:\\MSDOS.SYS")
print(attr)

Authors: Midas, Dmitry Maslov

setfileattr (strFileName, intFileAttr)

Description:
  Set file attributes.

Parameters:
  strFileName - filename
  iFileAttr - file attributes as number

Return value:
  contains true (at successful end) or false (at failure)

Example:

local result = shell.setfileattr("c:\\MSDOS.SYS", 32)
if result == true then
  print("File attributes are successfully established")
else
  print("error")
end

Authors: Midas, Dmitry Maslov

fileexists (strFileName)

Description:
  Check exist file or folder with specified name.

Parameters:
  strFileName - filename or folder name

Return value:
  contains true if file (folder) exist or false otherwise

Example:

local result = shell.fileexists("c:\\MSDOS.SYS")
if result then
  print("File exist")
else
  print("File not found")
end

Author: VladVRO

exec (strCommand, [strOperation], [boolNoShow], [bWaitOnReturn])

Description:
  Run external programm or open file with associate application. Allows to execute files, documents and links and to open folders in Windows Explorer.

Parameters:
  strCommand - filename or folder with possible startup parameters. Can contain %environments_variable%
  strOperation - executed operation from listed in the table:

OperationDescription
open Open. strCommand - filename or folder name (default)
edit Edit. Opens a file for editing. strCommand should be the document.
print Print. strCommand should be the document.
explore Opens a folder in Explorer window (with two panels). strCommand - file or folder
select Opens a folder in Explorer window and chooses the specified folder or a file. strCommand - file or folder
find Showing a dialog box "File Search". strCommand should specify a folder path from which search will begin
properties Showing file|folder "Properties" window. strCommand - file or folder
other Other operation available in context menu of a file. For example "Play" operation available for media files.

  boolNoShow - true | false (default) - silent or show a window of the started program
  bWaitOnReturn - true | false (default) - boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script

Return value:
  The first contains
    - at successful end: true or (if function has been started with parameter bWaitOnReturn = true), exit code of process
    - at failure: false
  The second value contains error/success message of operation;
  or contains the output text of the console application (if execute console applications with parameters boolNoShow = true and bWaitOnReturn = true)

Example:

-- run application
shell.exec("clipbrd.exe")
shell.exec("CMD /c IPCONFIG /all > out.txt", nil, true, false)

-- show result of console application
print( shell.exec("CMD /c DIR", nil, true, true) )
print( shell.exec("cscript /nologo %WINDIR%\\system32\\eventquery.vbs /?", nil, true, true) )

-- analysis of the exit code of process
if shell.exec("ping -n 1 localhost", nil, true, true) == 0 then
    print("Network works") else print("Network does not work")
end

-- open folder
shell.exec("%TEMP%")
shell.exec("%USERPROFILE%", "find")
shell.exec("%WINDIR%\\regedit.exe", "explore")
shell.exec("%ProgramFiles%", "properties")
shell.exec("%ComSpec%", "select")

-- open URL link
shell.exec("http://scite-ru.org/")

-- send e-mail
shell.exec("mailto:support@gmail.com")

-- open file (with associate application)
shell.exec("%WINDIR%\\WindowsUpdate.log")

-- print file
shell.exec("%WINDIR%\\win.ini", "print")

-- edit file
shell.exec("%WINDIR%\\winnt.bmp", "edit")

Authors: Dmitry Maslov

findfiles (strFindMask)

Description:
  Searches for files and folders with mask and returned result as the table.

Parameters:
  strFindMask - file or folder name, or mask with wildcard symbol, which replaces one or several symbols: (?) can present any single symbol; (*) it is used for present of any symbol or group of symbols.

Return value:
  Returns the list of the found files and folders as the numbered table (numbering begins with 1), where
  each element is structure containing:

ValueDescription
name name of a folder or file
isdirectory attribute a file it or a folder (true if a folder, false if a file)
attributes attributes (see lower)
size size of a file in bytes

  Attributes are submitted as number which can be a combination of the following values:

ValueDescription
0x00000001 A file or directory that is read-only. For a file, applications can read the file but cannot write to it or delete it. For a directory, applications cannot delete it, but applications can create and delete files from that directory.
0x00000002 A file or directory that is hidden. Files and directories marked with this attribute do not appear in an ordinary directory listing.
0x00000004 A file or directory that the operating system uses a part of or uses exclusively.
0x00000010 This item is a directory.
0x00000020 A file or directory that needs to be archived. Applications use this attribute to mark files for backup or removal.
0x00000080 A file or directory that does not have other attributes set.
0x00000100 A file that is being used for temporary storage. The operating system may choose to store this file's data in memory rather than on mass storage, writing the data to mass storage only if data remains in the file when the file is closed.
0x00000200 A file that is a sparse file.
0x00000400 A file or directory that has an associated reparse point.
0x00000800 A file or directory that is compressed. For a file, all of the data in the file is compressed. For a directory, compression is the default for newly created files and subdirectories.
0x00001000 The data in this file is not available immediately. This attribute indicates that the file data is physically moved to offline storage. This attribute is used by Remote Storage, which is hierarchical storage management software.
0x00002000 A file or directory that is not indexed by the content indexing service.
0x00004000 A file or directory that is encrypted. For a file, all data streams in the file are encrypted. For a directory, encryption is the default for newly created files and subdirectories.
0x00010000 This file virtual.

  At failure return nil

Example:

local t = shell.findfiles("C:\\*")
if t then
  table.sort(t,
    function(v1,v2)
      if v1.isdirectory ~= v2.isdirectory then
        return v1.isdirectory
      else
        return v1.name:lower() < v2.name:lower()
      end
    end
  )
  table.foreachi(t,
    function(i,v)
      if v.isdirectory then
        print(string.format("D%5x %s", v.attributes, v.name))
      else
        print(string.format(" %5x %-30s", v.attributes, v.name), v.size)
      end
    end
  )
else
  print("not found")
end

Author: VladVRO

Download

Current version Shell: 1.2

shell.dll
Source code