Вы находитесь на странице: 1из 3

FSO stands for File System Object.

This is used to support text file creation an


d manipulation .
The FSO Object Model has a rich set of properties, methods and events to process
folders and files.
***************
Create a folder
***************
Dim fso,f
Set fso=CreateObject("Scripting.FileSystemObject")
Set f =fso.CreateFolder("C:\arun")
Set f=Nothing
Set fso=Nothing

***************************************************
Create the folder and Check if folder already exist
***************************************************
Dim fso,f
Set fso=createobject("Scripting.FileSystemObject")
If (fso.folderexists("c:\arun")) Then
msgbox "Folder Already Exist"
else
Set f=fso.createfolder("C:\arun")
msgbox "Folder is created"
End If
Set fso=nothing
***************************************************
Create the folder and Check if folder already exist
and create a word file and write in it
***************************************************
Dim fso,f
Set fso=createobject("Scripting.FileSystemObject")
If (fso.folderexists("c:\arun")) Then
msgbox "Folder Already Exist"
else
Set f=fso.createfolder("C:\arun")
End If
Set f=fso.createtextfile("c:\arun\arun.txt")
f.write"Name"
f.write "Arun"
f.writeblanklines 1
f.writeline "Aman"
f.close
Set fso=nothing

***************************************************
For Reading
***************************************************
Dim fso,f
Const ForReading=1
Set fso=createobject("Scripting.FileSystemObject")
If (fso.folderexists("c:\arun")) Then
msgbox "Folder Already Exist"
else
Set f=fso.createfolder("C:\arun")
End If
Set f=fso.createtextfile("c:\arun\arun.txt")
f.write"Name"
f.write "Arun"
f.writeblanklines 1
f.writeline "Aman"
f.close
Set f=fso.OpenTextFile("c:\arun\arun.txt",ForReading,True)
r=f.readall
msgbox r
f.close
Set fso=nothing

***************************************************
For Appending
***************************************************
Dim fso,f
Const ForReading=1 , ForWriting=2 , ForAppending=8
Set fso=CreateObject("Scripting.FileSystemObject")
set f=fso.OpenTextFile("c:\arun\arun.txt",ForAppending,true)
f.Write "arun khanna"
Set f=nothing
Set fso=nothing
***************************************************
For deletion of file and folder
***************************************************
Dim fso,f
Set fso=CreateObject("Scripting.FileSystemObject")

fso.DeleteFile("c:\arun\arun.txt")
fso.DeleteFolder("c:\arun")
Set f=nothing
Set fso=nothing
***************************************************
With Excel
***************************************************
Set ex=CreateObject("Excel.Application")
Set a=ex.Workbooks.Open("c:\arun.xls")
Set b=a.Worksheets("login")
Dim aname,pwd
For i=1 to 3
aname=b.cells(i,1).value
pwd=b.cells(i,2).value
msgbox aname & " : " & pwd
Next
a.Close
***************************************************
With Access
***************************************************
Dim con,rs
Set con=CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open "c:\arun.mdb"
rs.Open "Select * from login",con
Do while not rs.EOF
print rs.Fields("name")
print rs.Fields("password")
rs.MoveNext
Loop

Вам также может понравиться