Skip to main content

Files and Folders related Functions..

Files and Folders related Functions

VBScript Runtime Properties

Like the objects in the WSH core object model, VBScript runtime objects provide an extensive supply of properties. You can use the properties to view or change numerous file system attributes. These properties are listed here.
· AtEndOfLine. Returns a value of either true or false depending on whether the file pointer precedes the TextStream file’s end-of-line marker.
· AtEndOfStream. Returns a value of either true or false depending on whether the end of a TextStream file has been reached.
· Attributes. Retrieves or sets file and folder attributes.
· AvailableSpace. Retrieves the amount of free space available on a drive.
· Column. Retrieves the current column position within a
TextStream
file.

· CompareMode. Retrieves or sets the comparison mode used to compare a Dictionary object’s string keys.
· Count. Returns a count of the items in a collection or Dictionary object.
· DateCreated. Returns a file or folder’s creation date and time.
· DateLastAccessed. Returns the date and time that a file or folder was last accessed.
· DateLastModified. Returns the date and time that a file or folder was last modified.
· Drive. Returns the drive letter representing the drive where a file or folder is stored.
· DriveLetter. Returns a drive’s drive letter.
· Drives. Creates a Drives collection representing the computer’s Drive objects.
· DriveType. Returns a value indicating a drive’s type.
· Files. Creates a Files collection representing the File objects stored inside a folder.
· FileSystem. Returns the file system type implemented on a drive.
· FreeSpace. Returns the amount of free space available to the user on a drive.
· IsReady. Returns a value of either true or false depending on whether a drive is available.
· IsRootFolder. Returns a value of either true or false identifying whether a folder is the root folder.
· Item. Retrieves or sets an item based on the specified Dictionary object key.
· Key. Sets a Dictionary object key.
· Line. Returns the current line number in the TextStream file.
· Name. Retrieves or sets a file or folder’s name.
· ParentFolder. Retrieves a file or folder’s parent folder object.
· Path. Retrieves the path associated with a file, folder, or drive.
· RootFolder. Retrieves the Folder object associated with the root folder on the specified drive.
· SerialNumber. Retrieves a disk volume’s serial number.
· ShareName. Retrieves a network drive’s share name.
· ShortName. Retrieves a file’s or folder’s 8.3 character short name.
· ShortPath. Retrieves the short path associated with a file’s or folder’s 8.3 character name.
· Size. Retrieves a file’s or folder’s byte size.
· SubFolders. Establishes a Folders collection consisting of all the folders located inside a specified folder.
· TotalSize. Returns the total number of bytes left on a drive.
· Type. Retrieves information about a file’s or folder’s type.
· VolumeName. Retrieves or sets a drive’s volume name.

VBScript Runtime Methods

The methods that belong to the VBScript runtime objects are listed here.

VBScript Run-time Methods
· Add (Dictionary). Adds a key and item pair to a Dictionary object.
· Add (Folders). Adds a Folder to a collection.
· BuildPath. Appends a name to the path.
· Close. Closes an open TextStream file.
· Copy. Copies a file or folder.
· CopyFile. Copies one or more files.
· CopyFolder. Recursively copies a folder.
· CreateFolder. Creates a new folder.
· CreateTextFile. Creates a file and a TextStream object that can be used to read and write to the file.
· Delete. Deletes a file or folder.
· DeleteFile. Deletes a file.
· DeleteFolder. Deletes a folder’s contents.
· DriveExists. Returns either true or false depending on the existence of a drive.
· Exists. Returns either true or false depending on whether a key exists in a Dictionary object.
· FileExists. Returns either true or false depending on whether a file can be found.
· FolderExists. Returns a value of true or false depending on whether a folder can be found.
· GetAbsolutePathName. Returns a complete path name.
· GetBaseName. Retrieves a filename less its file extension.
· GetDrive. Returns the Drive object associated with the drive in the specified path.
· GetDriveName. Retrieves the name of a drive.
· GetExtensionName. Retrieves a file’s extension.
· GetFile. Retrieves a File object.
· GetFileName. Retrieves the last filename or folder of the specified path.
· GetFileVersion. Retrieves a file’s version number.
· GetFolder. Retrieves the Folder object associated with the folder in the specified path.
· GetParentFolderName. Retrieves the name of the parent folder.
· GetSpecialFolder. Retrieves a special folder’s name.
· GetTempName. Retrieves the name of a temporary file or folder.
· Items. Returns an array containing the items in a Dictionary object.
· Keys. Returns an array containing the keys in a Dictionary object.
· Move. Moves a file or folder.
· MoveFile. Moves one or more files.
· MoveFolder. Moves one or more folders.
· OpenAsTextStream. Opens a file and returns a TextStream object that can be used to reference the file.
· OpenTextFile. Opens a file and returns a TextStream object that can be used to reference the file.
· Read. Returns a string containing x number of characters from a TextStream file.
· ReadAll. Reads the whole TextStream file and returns its contents.
· ReadLine. Reads a line in a TextStream file.
· Remove. Deletes a Dictionary object’s key, item pair.
· Skip. Skips x number of character positions when processing a TextStream file.
· SkipLine. Skips a line when processing a TextStream file.
· Write. Places a string in the TextStream file.
· WriteBlankLines. Writes x number of newline characters to the TextStream file.
· WriteLine. Writes a string in the TextStream file

Comments

Popular posts from this blog

Convert JSON to XML using QTP/UFT/VBScript

Sample Code : Dim strPage,strJSON,objIE strPage = "C:\Jay\JLoader.html" Set objIE = CreateObject("InternetExplorer.Application") objIE.Visible = True objIE.Navigate2 strPage While objIE.Busy : Wend strJSON = "{""FirstName"":""Jay"", ""LastName"":""Krishna""}" Set objWin = objIE.document.parentWindow objWin.execScript "var jsonStr2XML = function(strJSON) { return json2xml(JSON.parse(strJSON));};" Msgbox  oWin.jsonStr2XML(strJSON) objIE.Quit In Detail: Converting The most popular data interchange format JSON(JavaScript Object Notation) to XML using QTP/UFT. Parsing JSON in UFT could be a challenge so we will use JavaScript in UFT to make it perfect. SO We need :              Java Script API  - To Convert JSON to XML                         JavaScript Files :                         http://goessner.net/download/prj/jsonxml/j

Read Outlook mail attachment and Body using Vb Script or QTP

Set olApp = CreateObject("Outlook.Application") Set olns = olApp.GetNameSpace("MAPI") Set ObjFolder = olns.GetDefaultFolder(6) j = 0 For each item1 in ObjFolder.Items        iattachCnt = item1.Attachments.Count     Print "Attachments Count: " & iattachCnt     For i = 1 to iattachCnt         Print "FileName :    " & item1.Attachments(i).FileName         Print "Display Name:   " & item1.Attachments(i).DisplayName         Print "Size: " & item1.Attachments(i).Size     Next     Print " Body : " & item1.body     Print "--------------------------------------Mail Num - " & j & " -----------------------------------------------"     j = j+1    Next

Excel Sorting By Rows and Columns

Excel Sorting By Row: Const xlAscending = 1 Const xlNo = 2 Const xlSortRows = 2 Set objExcel = CreateObject(“Excel.Application”) objExcel.Visible = True Set objWorkbook = objExcel.Workbooks.Open(“C:\Jay\Docs1.xls”) Set objWorksheet = objWorkbook.Worksheets(1) objWorksheet.Cells(1,1).activate Set objRange = objExcel.ActiveCell.EntireRow objRange.Sort objRange, xlAscending, , , , , , xlNo, , , xlSortRows set objExcel=nothing Excel Sorting By Column : Const xlAscending = 1′represents the sorting type 1 for Ascending 2 for Desc Const xlYes = 1 Set objExcel = CreateObject(“Excel.Application”)’Create the excel object objExcel.Visible = True’Make excel visible Set objWorkbook = _ objExcel.Workbooks.Open(“C:\Jay\Docs1.xls”)’Open the document Set objWorksheet = objWorkbook.Worksheets(1)’select the sheet based on the index .. 1,2 ,3 … Set objRange = objWorksheet.UsedRange’which select the range of the cells has some data other than blank Set objRange2 = objExcel.Range

How to Read or Select Context Menu or Right Click Menu using QTP.

Select The Item in Right Click Menu or Context Menu: Window("sampleWindow").WinMenu("MenuObjType:=1).Select"File;New" Here MenuObjtype can be 1 r 2 r 3 .......n Check wether the Item is Exist or Not: If Window("sampleWindow").WinMenu("MenuObjType:=1).GetItemProperty("1","Exist") Then   Msgbox"Exist" Else  Msgbox"Does Not Exist" End If                                         Or If Window("sampleWindow").WinMenu("MenuObjType:=1).GetItemProperty("File","Exist") Then   Msgbox"Exist" Else  Msgbox"Does Not Exist" End If Get the Items in Context Menu: For i = 1 to 10 Print  Window("sampleWindow").WinMenu("MenuObjType:=" & i).GetItemProperty("1","Label") Then Next

How to Download a file using VbScript

Following is the code to download a file using Vbscript, without using QTP This code uses the HTMLDom and URLDownloadToFile method from urlmon API. Since VBScript does support calling Native API methods directly, here I am using  Excel macro to declare a function for the urlmon API and running the macro by Excel API from VBscript Step1: Create a new excel and open the visual basic editor, Insert Module and paste the following code the Module, save the excel file Private Declare Function URLDownloadToFile Lib “urlmon” Alias _                                            “URLDownloadToFileA” ( _                                            ByVal pCaller As Long, ByVal szURL As String, _                                            ByVal szFileName As String, _                                            ByVal dwReserved As Long, _                                            ByVal lpfnCB As Long) As Long Sub FileSave(strUrl, Des)     r = URLDownloadToFile(0, strUrl, Des, 0, a)