Open Directory Site ASP Tutorials

ASP | XML | VBScript | JavaScript | ADO | CSS | XMLDOM | PHP | Operating Systems

Home >> ASP >> ASP Folder Object

ASP Folder Object

 

The Folder Object

The Folder Object is used to access the properties of a folder.

Methods

Method Description

Copy Copies a folder

Delete Deletes a folder

Move Moves a folder

CreateTextFile Creates a text file and returns a TextStream Object to access the file

Properties

Property Description

Attributes Sets or returns the attributes of a folder

DateCreated Returns the date and time when the folder was created

DateLastAccessed Returns the date and time when the folder was last accessed

DateLastModified Returns the date and time when the folder was last modified

Drive Returns the drive letter where a specified folder resides

Files Returns a collection of all files in a folder

IsRootFolder Returns true if a folder is the root folder

Name Sets or returns the name of a folder

ParentFolder Returns the parent folder of a folder

Path Returns the path for a folder

ShortName Returns the short name of a folder (the earlier 8.3 naming convention)

ShortPath Returns the short path (the earlier 8.3 file naming convention)

Size Returns the size of a folder

SubFolders Returns a collection of all sub folders in a folder

Type Returns the type of a folder

Methods

The Copy Method

The Copy method copies a file or folder.

Syntax

object.Copy(destination, overwrite)

Part Description

object Required. The name of a File or Folder Object

destination Required. Where to copy the file or folder

overwrite Optional. Sets whether an existing file or folder can be overwritten. True indicates that the file/folder can be overwritten, False indicates that the file/folder can not be overwritten. True is default

Example

dim fs,txtfile

set fs=CreateObject("Scripting.FileSystemObject")

set txtfile=fs.GetFile("c:\testfile.txt")

txtfile.Copy("c:\mydocuments\test\test2.txt")

set txtfile=nothing

set fs=nothing

The Delete Method

The Delete method deletes a specified file or folder.

Syntax

object.Delete force

Part Description

object Required. The name of a File or Folder Object

force Optional. Sets whether a read-only file or folder are deleted. True indicates that a read-only file/folder are deleted, False indicates that it is not deleted. False is default

Example

dim fs,txtfile

set fs=CreateObject("Scripting.FileSystemObject")

set txtfile=fs.GetFile("c:\testfile.txt")

txtfile.Delete

set txtfile=nothing

set fs=nothing

The Move Method

The Move method moves a file or folder.

Syntax

object.Move destination

Part Description

object Required. The name of a File or Folder Object

destination Required. Where to move the file or folder

Example

dim fs, txtfile

set fs=CreateObject("Scripting.FileSystemObject")

Set txtfile = fs.GetFile("c:\testfile.txt")

txtfile.Move("c:\mydocuments\test\")

set txtfile=nothing

set fs=nothing

The CreateTextFile Method

The CreateTextFile method creates a file and returns a TextStream object that can be used to read from or write to the file.

Syntax

object.CreateTextFile(filename, overwrite, unicode)

Part Description

object Required. The name of a FileSystemObject or Folder Object

filename Required. Name of the file to create

overwrite Optional. Sets whether an existing file can be overwritten. True indicates that

the file can be overwritten, False indicates that the file can not be overwritten.

False is default

unicode Optional. Sets whether the file is created as a Unicode or an ASCII file. True

indicates that the file is created as a Unicode file, False indicates that the file is

created as an ASCII file. False is default

Example

dim fs, txtfile

set fs=CreateObject("Scripting.FileSystemObject")

set txtfile=fs.CreateTextFile("c:\somefile.txt")

set txtfile=nothing

set fs=nothing

Properties

The Attributes Property

The Attributes property sets or returns the attributes of files or folders.

Syntax

object.Attributes = newattributes

Part Description

object Required. The name of a File or Folder Object

=newattributes Optional. Sets the new value for the attributes of the specified object.

Can have any of the following values or a combination of the following

values: 0 = Normal file 1 = Read-only file 2 = Hidden file 4 = System

file 16 = Folder or directory 32 = File has changed since last backup

1024 = Link or shortcut 2048 = Compressed file

Example

dim fs, f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFile("c:\test.txt")

Response.Write("The attributes of the file are: ")

Response.Write(f.Attributes)

set f=nothing

set fs=nothing

The DateCreated Property

The DateCreated property returns the date and time when a file or folder was created.

Syntax

object.DateCreated

Part Description

object Required. The name of a File or Folder Object

Example

dim fs, f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFile("c:\test.txt")

Response.Write("The file was created on: ")

Response.Write(f.DateCreated)

set f=nothing

set fs=nothing

The DateLastAccessed Property

The DateLastAccessed property returns the date and time when a file or folder was last accessed.

Syntax

object.DateLastAccessed

Part Description

object Required. The name of a File or Folder Object

Example

dim fs, f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFile("c:\test.txt")

Response.Write("The file was last accessed on: ") Response.Write(f.DateLastAccessed)

set f=nothing

set fs=nothing

The DateLastModified Property

The DateLastModified property returns the date and time when a file or folder was last modified.

Syntax

object.DateLastModified

Part Description

object Required. The name of a File or Folder Object

Example

dim fs, f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFile("c:\test.txt")

Response.Write("The file was last modified on: ")

Response.Write(f.DateLastModified)

set f=nothing

set fs=nothing

The Drive Property

The Drive property returns the drive letter where a specified file or folder resides.

Syntax

object.Drive

Part Description

object Required. The name of a File or Folder Object

Example

dim fs, f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFile("c:\test.txt")

Response.Write("The file resides on drive: ")

Response.Write(f.Drive)

set f=nothing

set fs=nothing

The Files Property

The Files property returns a collection of all files in a specified folder.

Syntax

object.Files

Part Description

object Required. The name of a Folder Object

The IsRootFolder Property

The IsRootFolder property returns true if the specified folder is the root folder, false if not.

Syntax

object.IsRootFolder

Part Description

object Required. The name of a Folder Object

Example

dim fs,f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFolder("c:\asp\")

if f.IsRootFolder = true then

Response.Write("The folder is the root folder")

else

Response.Write("The folder is not the root folder")

end if

set f=nothing

set fs=nothing

The Name Property

The Name property sets or returns the name of a specified file or folder.

Syntax

object.Name =newname

Part Description

object Required. The name of a File or Folder Object

=newname Optional. Sets the new name of the specified file or folder

Example

dim fs, f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFile("c:\test.txt")

Response.Write("The file's name: ")

Response.Write(f.Name)

set f=nothing

set fs=nothing

The ParentFolder Property

The ParentFolder property returns the parent folder of a specified file or folder.

Syntax

object.ParentFolder

Part Description

object Required. The name of a File or Folder Object

Example

dim fs, f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFile("c:\asp\test.asp")

Response.Write("The file test.asp is in the folder: ")

Response.Write(f.ParentFolder)

set f=nothing

set fs=nothing

The Path Property

The Path property returns the path for a specified file, folder, or drive.

Syntax

object.Path

Part Description

object Required. The name of a Drive, File, or Folder Object

Example

dim fs,d

set fs=CreateObject("Scripting.FileSystemObject")

set d=fs.GetDrive("c:")

Response.Write("Path is " & d.Path)

set d=nothing

set fs=nothing

The ShortName Property

The ShortName property returns the short name of the file (the earlier 8.3 naming convention).

Syntax

object.ShortName

Part Description

object Required. The name of a File or Folder Object

Example

dim fs, f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFile("c:\asp\test_new_components.asp")

Response.Write("The short name for ")

Response.Write("test_new_components.asp is: ")

Response.Write(f.ShortName)

set f=nothing

set fs=nothing

The ShortPath Property

The ShortPath property returns the short path (the earlier 8.3 file naming convention).

Syntax

object.ShortPath

Part Description

object Required. The name of a File or Folder Object

Example

dim fs, f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFile("c:\asp\test.asp")

Response.Write("The short path for ")

Response.Write("c:\mydocuments\test.htm is: ")

Response.Write(f.ShortPath)

set f=nothing

set fs=nothing

The Size Property

The Size property returns the size of a file or folder in bytes.

Syntax

object.Size

Part Description

object Required. The name of a File or Folder Object

Example

dim fs, f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFile("c:\asp\test.asp")

Response.Write("The size of the file test.asp is: ")

Response.Write(f.Size) Response.Write(" bytes.")

set f=nothing

set fs=nothing

The SubFolders Property

The SubFolders property returns a collection of all subfolders in a specified folder.

Syntax

object.SubFolders

Part Description

object Required. The name of a Folder Object

The Type Property

The Type property returns information about the type of a file or folder.

Syntax

object.Type

Part Description

object Required. The name of a File or Folder Object

Example

dim fs, f

set fs=CreateObject("Scripting.FileSystemObject")

set f=fs.GetFile("c:test.txt")

Response.Write("The file test.txt is of type: ")

Response.Write(f.Type)

set f=nothing

set fs=nothing

Cheap Web Hosting Articles - Web Site Design & Web Hosting Tutorials - Domain Hosting