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

PDF Automation in QTP

                                                                            The most challenging issue with PDFs is that it could be of any kind, not just a tabular data; it could have plain text, images or even forms to fill up. So this makes a tester’s life a bit difficult, never mind, we will definitely find an easy of do it… Although there are already some better approaches we have to deal with PDF documents but I found many of us are facing so many difficulties using this. There are lots of queries coming at QTP forums asking for an easy way of doing it with PDFs. keeping those in my mind I started c...

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 :  ...

Download Test Resource From QC Using QTP

'########################################################################### '* Function Name: QCGetResource '* Designer: Jay '* Date 09-May-2012 '* This script will Download QC Test Resource to a local dir '########################################################################### Function QCGetResource(resourceName,saveTo)     Set qcConn = QCUtil.QCConnection     Set oResource = qcConn.QCResourceFactory     Set oFilter = oResource.Filter     oFilter.Filter("RSC_FILE_NAME") = resourceName     Set oResourceList = oFilter.NewList     If oResourceList.Count = 1 Then         Set oFile = oResourceList.Item(1)         oFile.FileName = resourceName         oFile.DownloadResource saveTo, True     End If         Set qcConn = Nothing     Set oResource = Nothi...

compare Two Text files using Vb Script

Public Function CompareFiles (FilePath1, FilePath2) Dim FS, File1, File2 Set FS = CreateObject(“Scripting.FileSystemObject”) If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then CompareFiles = True Exit Function End If Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0) Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0) CompareFiles = False Do While File1.AtEndOfStream = False Str1 = File1.Read(1000) Str2 = File2.Read(1000) CompareFiles = StrComp(Str1, Str2, 0) If CompareFiles <> 0 Then CompareFiles = True Exit Do End If Loop File1.Close() File2.Close() End Function Return value: The function returns 0 or False if the two files are identical, otherwise True. Example: File1 = “C:\countries\apple1.jpg” File2 = “C:\countries\apple3.jpg” If CompareFiles(File1, File2) = False Then MsgBox “Files are identical.” Else MsgBox “Files are different.” End If    Source: Mercury Forum’s KB articles

CreateImageFromClipBoard using QTP

'-------------------------------------------------------------------------' Method : CreateImageFromClipBoard' Author : Jai Purpose : It gets the clipboard image and convert as a image file.' Parameters: FileName - String, contains the BMP file name' iIndex - Integer, contains the Worksheet index' Returns : String. The replaced file name it gives.' Caller : - Nil' Calls : - Nil' ------------------------------------------------------------------------- Sub CreateImageFromClipBoard(sFileName) Dim wshShell,ShellReturnCode, sCmdExec Set WshShell = WScript.CreateObject("WScript.Shell") sCmdExec = "D:\autostuff\i_view32.exe /silent /clippaste /convert="& sFileName ShellReturnCode = WshShell.Run(sCmdExec, 1, True) End Sub