Thursday, January 3, 2019


File system object in vb script


Filesystemobject can be used to work with drives, folders, and files.

Filesystemobject  has methods and properties that allow us to create, delete, gain information about, and generally manipulate drives, folders, and files.

Important Methods of filesystemobject in vb script
  1. CopyFile
  2. CopyFolder    
  3. CreateFolder
  4. CreateTextFile
  5. DeleteFile
  6. DeleteFolder 
  7. DriveExists
  8. FileExists
  9. FolderExists
  10. GetAbsolutePathName
  11. GetBaseName   
  12. GetDrive
  13. GetDriveName
  14. GetExtensionName
  15. GetFile
  16. GetFileName
  17. GetFolder    
  18. GetParentFolderName
  19. GetSpecialFolder
  20. GetTempName
  21. MoveFile
  22. MoveFolder
  23. OpenTextFile 

Working with files


Creating and writing to file
 You can create a text file using this object.

Set obj = createobject("scripting.filesystemobject")
set f = obj.createtextfile("g:\salunke.txt")                      ' create a file
f.write str                ' write some data into file
set f= nothing           ' release memory
set obj = nothing

Reading from the file character by character
Set fo = createobject("scripting.filesystemobject")
  set stream1= fo.OpenTextFile("c:\abc.txt",1)
  msgbox stream1.AtEndOfStream
  Do While   (stream1.AtEndOfStream <> true )
    msgbox stream1.Read(1)
  loop
  stream1.Close
  Set stream1 = nothing

Appending data to file

set stream1= fo.OpenTextFile("c:\abc.txt",8)
  stream1.Write("append it")
                stream1.Close
  Set stream1 = nothing
  Set fo = nothing

Working with Folders

We can create, delete folders.

Working with Drives



Related Posts:

  • How we can define array in vb script How we can define array in vb script Arrays are used to store multiple values in the same variable.We can define array in vb script in 4 different ways. dim a(10)  - static array of 11 elements dim b()  … Read More
  • Date time functions in vb script Date time functions in vb script It is very important that you know how to work with date and time in VBScript as most of the VBScript programs will have date and time involved in it.Below is the list of all date and … Read More
  • Classes in VBScript Classes in VBScript Here is an example that shows how we can create a class in QTP. Once we define the class, we can create its objects and then access its method and properties. 'declare the class book. Class Bo… Read More
  • Error handling in VBScript Error handling in VBScript VBScript provides below statements and keywords to handle errors. on error resume next Err object - err.description, err.number Sample code to handle the error is given below If er… Read More
  • What are the different operators in vbscript? What are the different operators in vbscript? At broad level there are 3 kinds of operators as mentioned below. Arithmetic Operators Comparison Operators Logical Operators Arithmetic Operators in the order of pre… Read More

1 comment:

Blog Archive

Translate

Popular Posts

Total Pageviews

152,293

Blog Archive