FSO Object model Methods Properties FileSystem Object Example

The scripting

object do not have direct deal with communication between client and we server

, but provides additional functionality to the scripting language.FileSystem

object is one of the scripting object which provides access from ASP script

to the hard disc file system of the server.This object allows you to work with

files , directories and subdirectories.This will allow the following tasks.

1)Get and

manipulate information about all drives in the server.

2)Get and

manipulate information about all all folders and subfolders on a drive.

3)Get and

manipulate information about all files inside a folder.

The syntax for creating FileSystemObject is :

Set

objFSO = CreateObject(“Scripting.FileSystemObject”)


Object model of FileStystemObject

Object model

is group or related objects that are working together to provide access to

a certain group of functions on the server.The object model associated with

FileSystemObject model are :

1)Drive

object – contains the information about a drive in the server.The information

includes -the free space available,name of the drive,type of file system that

exist in the drive,physical type of drive,indication whether drive is ready.

2)Drives

collection – contains one drive object for each drive on the system which

are local or both fixed and removable .

3)Folder

object – allows access to all properties of folders and subfolders. The properties

include name of folder,the collection of files within it,size of folders and

its attributes.Also this allows to copy , delete or move folders within file

system.

4)Folders

Collection – contains a set of folder objects.

5)File

object – allows access to all the properties of an individual file -name of

file,path to file,size of the file.also this allows to copy,delete or move

files in file system.

6)Files

Collection – contains all file objects within a folder.

Top


Methods

 

 

Method Syntax Description
BuildPath() FileSystemobject.BuildPath(path,

name)

Appends

a name to an existing path.Path can be absolute or relative and need not

specify an existing folder.

CopyFile() FileSystemobject.CopyFile(From,To,overwrite) Copies

one or more files from one location to another.To avoid overwriting set

overwrite as Fasle.The default value is True. 

Copyfolder() FileSystemobject.CopyFile(From,To,overwrite) copies

a folder from one location to another

CreateFolder() FileSystemobject.CreateFolder(foldername) Creates

a folder

CreateTextFile() FileSysetmobject.CreateTextFile(name,overwrite,unicode) Creates

a specified file name and returns a TextStream object that can be used

to read from or write to the file.overwrite and unicode are optional.

DeleteFile() FileSystemobject.DeleteFile(

filename, force)

Deletes

a specified file.

DeleteFolder() FileSystemobject.DeleteFolder(

foldername, force)

Deletes

a specified folder and its contents

DriveExist() FileSystemobject.DriveExists(drivespec) Returns

True if the specified drive exists; False if it does not.Drivespec is

A drive letter or a complete path specification

FileExist() FileSystemobject.FileExists(filespec) Returns

True if a specified file exists; False if it does not.Filespec is The

name of the file whose existence is to be determined. A complete path

specification (either absolute or relative) must be provided if the file

isn’t expected to exist in the current folder.

FolderExist() FileSystemobject.FolderExists(folderspec) Returns

True if a specified folder exists; False if it does not.folderspec is

the The name of the folder whose existence is to be determined. A complete

path specification (either absolute or relative) must be provided if the

folder isn’t expected to exist in the current folder.

getabsolutepathsname() FileSystemobject.GetAbsolutePathName(pathspec) Returns

a complete and unambiguous path from a provided path specification.

getBaseName() FileSystemobject.GetBaseName(pathname) Returns

a string containing the base name of the last component, less any file

extension, in a path.

GetDrive() FileSystemobject.GetDrive

(drivespec)

Returns

a Drive object corresponding to the drive in a specified path

GetDriveName() FileSystemobject.GetDriveName(path) Returns

a string containing the name of the drive for a specified path

GetFile() FileSystemobject.GetFile(filespec) Returns

a File object corresponding to the file in a specified path.

GetFileName() FileSystemobject.GetFileName(pathspec) Returns

the last component of specified path that is not part of the drive specification

GetFolder() FileSystemobject.GetFolder(folderspec) Returns

a Folder object corresponding to the folder in a specified path.

GetParentFolderName() FileSystemobject.GetParentFolderName(path) Returns

a string containing the name of the parent folder of the last component

in a specified path

GetTempName() FileSystemobject.GetTempName Returns

a randomly generated temporary file or folder name that is useful for

performing operations that require a temporary file or folder.

MoveFile() FileSystemobject.MoveFile

(From, To)

Moves one

or more files from one location to another.From is the path to the file

or files to be moved.To is the path where the file or files are to be

moved. 

MoveFolder() FileSystemobject.MoveFolder

(From,To)

Moves one

or more folders from one location to another

OpenTextFile() FileSysetmobject.OpenTextFile(name,

iomode,create,format)

Opens a

specified file and returns a TextStream object that can be used to read

from or append to the file.iomode,create & format are optional.iomode

Indicates input/output mode( either ForReading or ForAppending.).create

indicates whether a new file can be created if the specified filename

doesn’t exist. The value is True if a new file is created; False if it

isn’t created. The default is False.One of three Tristate values used

to indicate the format of the opened file. If omitted, the file is opened

as ASCII.

CreateTextFile() FileSystemobject.CreateTextFile(name,overwrite,unicode) overwrite

& unicode are optional.If overwrite value is True then the file can

be overwritten; False then it can’t be overwritten. If omitted, existing

files are not overwritten.

It the unicode value is True then the file is created as

a Unicode file; If False then it’s created as an ASCII file. If omitted,

an ASCII file is assumed.

Top


Asp FileSystem Object – Properties

1)Properties

of FileSystemobject object

1)Drives

property  – Returns a Drives collection consisting of all Drive objects

available on the local machine

The syntax is :

FileSystemObject.Drives

2)

Properties of Files and Folder objects

 

 

Property Syntax Description
Name object.Name Sets or

returns the name of a specified file or folder. Read/write.To set a new

vale object.Name = newname.

Size object.Size For files,

returns the size, in bytes, of the specified file. For folders, returns

the size, in bytes, of all files and subfolders contained in the folder.The

object is always a File or Folder object

Type object.Type Returns

information about the type of a file or folder. For example, for files

ending in .TXT, “Text Document” is returned.The object is always a File

or Folder object

DateCreated object.DateCreated Returns

the date and time that the specified file or folder was created. Read-only.

The object is always a File or Folder object.

DateLastModified object.DateLastModifed Returns

the date and time that the specified file or folder was last modified.

Read-only.

The object is always a File or Folder object.

DateLastAccessed object.DateLastAccessed Returns

the date and time that the specified file or folder was last accessed.

Read-only.

The object is always a File or Folder object.

Path object.Path Returns

the path for a specified file, folder, or drive.The object is always a

File, Folder, or Drive object.

Drive object.Drive Returns

the drive letter of the drive on which the specified file or folder resides.

Read-only.The object is always a File or Folder object.

ParentFolder object.ParentFolder Returns

the folder object for the parent of the specified file or folder. Read-only.The

object is always a File or Folder object

SubFolder object.SubFolders  Returns

a Folders collection consisting of all folders contained in a specified

folder, including those with Hidden and System file attributes set.The

object is always a Folder object.

Attribute object.Attributes  Sets or

returns the attributes of files or folders. Read/write or read-only, depending

on the attribute.Where object is the name of a File or Folder object.

object.Attributes = newattributes sets new value.

Files object.Files  Returns

a Files collection consisting of all File objects contained in the specified

folder, including those with hidden and system file attributes set.The

object is always a Folder object

Top


The following is an example for displaying listing of files in

the current directory.

<html>

<head><title>Display files in the

current directory</title>

</head>

<body>

<%

dim strpathinfo,strphysicalpath

strvirtualpath=request.servervariables(“PATH_INFO”)

strphysicalpath=server.mapPath(strvirtualpath)

dim

objFSO,objFile,objFileItem,objFolder,objFoldercontents

set

objFSO=createobject(“scripting.filesystemobject”)

set objFile=objFSO.getfile(strphysicalpath)

set objFolder=objFile.parentfolder

set objFoldercontents=objFolder.files

%>

<table

border=1>

<tr>

<td><b>File name</b></td><td><b>Size</b></td><td><b>Creation

Date</b></td><td><b>Last Accessed</b></td><td><b>Last

modified</b></td>

<tr><tr>

<%

for each item in objFoldercontents%>

<tr>

<td><%=item.name%></td>

<td><%=item.size%></td>

<td><%=item.datecreated%></td>

<td><%=item.datelastaccessed%></td>

<td><%=item.datelastmodified%></td>

<%next%>

</table>

</body>

</html>

Top


 

Leave a Comment