| ファイルアクセスコンポーネント | |
|
ネイティブ ASP オブジェクト (Request、Response など) および各種のインストール可能なコンポーネント (Ad Rotator、Browser Capabilities など) に加え、第 3 のオブジェクトのグループにもアクセスできます。これらのオブジェクトは、Microsoft Scripting Runtime DLL ( すべてのファイル操作は、 FileSystemObject オブジェクトによって実行されます。アプリケーションにはこの中の 1 つのオブジェクトしかなく、そのオブジェクトがシステムのファイル構造に対するアプリケーションの "ウィンドウ" となります。このオブジェクトを使用すると、ファイルを開く、ファイルを閉じるなどの簡単な機能を実行できます。ただし、このオブジェクトの本当の強みは、Drive、Folder、および File といった他のファイル操作オブジェクトをインスタンス化できることです。アプリケーションでは、これらのオブジェクトにより、コマンド行インターフェイスを使用して得られるファイルシステムに対する能力をほとんど確保できます。 | |
| アクセサリファイルおよび必要な DLL ファイル | |
|
|
| インストール可能なコンポーネントのインスタンス化 | |
|
FileSystemObject コンポーネントのインスタンスを保持するオブジェクト変数を作成するには、Server オブジェクトの CreateObject メソッドを使用します。CreateObject メソッドの構文を次に示します。 Set objMyObject = Server.CreateObject(strProgId) ここで、各値の意味は次のとおりです。
例 <%
' The following code uses the CreateObject method of
' the Server object to instantiate a FileSystemObject.
Dim fsFileSystemObject
Set fsFileSystemObject = _
Server.CreateObject("Scripting.FileSystemObject")
%>
CreateObject メソッドの使用方法の詳細については、第 9 章の該当する項を参照してください。 |
|
| コメントおよびトラブルシューティング | |
|
|
|
| AtEndOfLine (TextStream オブジェクト) | |
| tsObj.AtEndOfLine | |
|
ファイルポインタが現在の行の末尾にあるかどうかを示すブール値です。これは読み取り専用のプロパティです。 |
|
| パラメータ | |
|
なし |
|
| 例 | |
|
次のコードは、FileSystemObject と TextStream オブジェクトをインスタンス化します。その後、Read メソッドを使用して、行の末尾に到達するまで一度に 1 文字ずつ読み取ります。AtEndOfStream プロパティと AtEndOfLine プロパティの使用方法が同じことが分ります。 <%
' Set up constants.
Const constForReading = 1
Const constTristateFalse = 0
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim tsObject ' TextStream Object
Dim strReturned ' String variable to hold file contents
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the OpenTextFile method of fsoObject,
' create a text file.
Set tsObject = _
fsoObject.OpenTextFile("d:\docs\test.txt", _
constForReading, constTristateFalse)
' Read one character at a time until the end of the
' line has been reached.
Do While Not tsObject.AtEndOfLine
StrReturned = strReturned & tsObject.Read(1)
Loop
|
|
| メモ | |
|
読み取り以外の目的で開いたテキストファイルで AtEndOfLine プロパティを使用しようとすると、エラーが発生します。 AtEndOfLine プロパティは、ファイルの最後に到達したことを通知しません。 |
|
| AtEndOfStream (TextStream オブジェクト) | |
| tsObj.AtEndOfStream | |
|
現在のテキストファイルの最後に到達したかどうかを示すブール値です。これは読み取り専用のプロパティです。 |
|
| パラメータ | |
|
なし |
|
| 例 | |
|
次のコードは、FileSystemObject と TextStream オブジェクトをインスタンス化します。その後、Read メソッドを使用して、ファイルの最後に到達するまで一度に 1 文字ずつ読み取ります。AtEndOfStream プロパティと AtEndOfLine プロパティの使用方法が同じことが分ります。 <%
' Set up constants.
Const constForReading = 1
Const constTristateFalse = 0
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim tsObject ' TextStream Object
Dim strReturned ' String variable to hold file contents.
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the OpenTextFile method of fsoObject, create
' a text file.
Set tsObject = _
fsoObject.OpenTextFile("d:\docs\test.txt", _
constForReading, constTristateFalse)
' Read one character at a time until the end of the
' file has been reached
Do While Not tsObject.AtEndOfStream
StrReturned = strReturned & tsObject.Read(1)
Loop
|
|
| メモ | |
|
読み取り以外の目的で開いたテキストファイルで AtEndOfStream プロパティを使用しようとすると、エラーが発生します。 |
|
| Attributes (File オブジェクト、Folder オブジェクト) | |||||||||||||||||||||||||||||||
Normal | |||||||||||||||||||||||||||||||
|
さまざまなファイルシステムの属性を表す値の組み合わせを保持する整数です。このプロパティは、該当するファイル属性によって読み取り専用、または読み書き可能になります。 次の表に、Attributes プロパティが保持できる値を示します。File オブジェクトまたは Folder オブジェクトに特定の値が保持されているかどうかを判断するには、ビットごとの And 演算子を使用して、Attributes プロパティの値と関心のある特定の定数を比較します。結果が True の場合、該当する属性は True となります。次の例を参照してください。
|
|||||||||||||||||||||||||||||||
| パラメータ | |||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||
| 例 | |||||||||||||||||||||||||||||||
|
次のコードは、最初に File オブジェクトで、次に Folder オブジェクトで Attributes プロパティを使用します。 <%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim filObject ' File Object
Dim fdrObject ' Folder Object
' Declare constants.
Const Hidden = 2
Const Archive = 32
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFile method of fsoObject, initialize the
' File object.
Set filObject = fsoObject.GetFile("d:\docs\test.txt")
' Set the Hidden (value = 2) and Archive (value = 32)
' attributes for the Test.TXT file.
filObject.Attributes = (Hidden + Archive)
' Using the GetFolder method of fsoObject, initialize
' the Folder object.
Set fdrObject = fsoObject.GetFolder("d:\docs")
' Determine whether the folder is itself hidden.
If (fdrObject.Attributes And Archive) Then
' Folder is hidden.
Else
' Folder is NOT hidden.
End If
|
|||||||||||||||||||||||||||||||
| メモ | |||||||||||||||||||||||||||||||
|
File オブジェクトのみを扱う読み取り専用属性を Folder オブジェクトで使用しようとすると、結果は常に False 値となります。ただし、File オブジェクトまたは Folder オブジェクト用のいずれかの読み取り専用属性を設定しようとすると、結果はエラーになります。 ファイルアクセスコンポーネントで使用する定数は、明示的に宣言する必要があります。 |
|||||||||||||||||||||||||||||||
| AvailableSpace (Drive オブジェクト) | |
| drvObj. AvailableSpace | |
|
現在のドライブに残っている領域のバイト数です。使用可能な領域が 2GB を超えるドライブの場合、この数字は不正確です。これは読み取り専用のプロパティです。 |
|
| パラメータ | |
|
なし |
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim drvObject ' Drive Object
Dim lngAvailBytes ' Number of bytes available
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetDrive method of fsoObject, initialize a
' Drive object.
Set drvObject = fsoObject.GetDrive("\\PublicDocs")
' Retrieve the amount of space (in bytes) available
' on the drive.
lngAvailBytes = drvObject.AvailableSpace
|
|
| メモ | |
|
AvailableSpace プロパティの値と FreeSpace プロパティの値が異なるのは、ドライブがクオータをサポートしている場合だけです。実際上、この 2 つのプロパティを互換的に使用できます。 |
|
| DateCreated (File オブジェクト、Folder オブジェクト) | |
| Obj.DateCreated | |
|
ファイルまたはフォルダが作成された日付を表す日付値です。これはオペレーティングシステムで制御される読み取り専用値です。 |
|
| パラメータ | |
|
なし |
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject.
Dim fdrObject ' Folder object.
Dim datCreated ' Date variable.
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFolder method of fsoObject, initialize
' a Folder object
Set fdrObject = fsoObject.GetFolder("c:\Docs")
' Retrieve the date the folder was created.
datCreated = fdrObject.DateCreated
|
|
| メモ | |
|
このプロパティの値は、ファイルが現在のドライブに書き込まれた日付でなく、ファイルが作成された日付を示します。 |
|
| Drive (File オブジェクト、Folder オブジェクト) | |
| Obj.Drive | |
|
File オブジェクトまたは Folder オブジェクトが関連付けられている Drive を返します。このプロパティは読み取り専用です。 |
|
| パラメータ | |
|
なし |
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim filObject ' File Object
Dim objDrive ' Drive name
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFile method of fsoObject, initialize
' a File object.
Set filObject = fsoObject.GetFile("PublicDocs.txt")
' Retrieve the drive name with which the File object
' is associated.
Set objDrive = filObject.Drive
' Note that this drive is actually the current drive
' in this case.
|
|
| メモ | |
|
Drive プロパティは、物理ドライブ、ローカルドライブ、マップドライブ、またはネットワーク共有を表すことができます。 Drive オブジェクトのデフォルトのプロパティは Path であるため、次のようにドライブ名を文字列に割り当てることができます。 strDrive = filObject.Drive これは、実際には次の簡略化バージョンです。 strDrive = filObject.Drive.Path ただし、Drive オブジェクトを操作する場合、Set ステートメントを使用して、オブジェクト変数への参照を割り当てる必要があります。次に例を示します。 Set objDrive = filObject.Drive |
|
| FileSystem (Drive オブジェクト) | |
| drvObj.FileSystem | |
|
現在のドライブをフォーマットするファイルシステムタイプを表す文字列です。認識できるファイルシステムタイプは、CDFS、NTFS、FAT、および FAT32 です。これは読み取り専用のプロパティです。 |
|
| パラメータ | |
|
なし |
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim drvObject ' Drive Object
Dim strFileSys ' File system of drive
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetDrive method of fsoObject, initialize
' a Drive object.
Set drvObject = fsoObject.GetDrive("\\PublicDocs")
' Retrieve the file system for the drive. This value
' will contain one of the following strings:
' NTFS, FAT, or CDFS.
strFileSys = drvObject.FileSystem
|
|
| メモ | |
|
Drive オブジェクトの FileSystem プロパティの値を使用すると、現在のドライブで利用できるクラスターサイズとセキュリティ機能を反映させることができます。 |
|
| IsReady (Drive オブジェクト) | |
| drvObj.IsReady | |
|
現在のドライブが読み取り可能または書き込み可能かを表すブール値です。このプロパティを使用すると、たとえば、ドライブにフロッピーディスクまたは CD が挿入されているかどうかを判断できます。これは読み取り専用のプロパティです。 |
|
| パラメータ | |
|
なし |
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim drvObject ' Drive Object
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject(
"Scripting.FileSystemObject")
' Using the GetDrive method of fsoObject, initialize a
' Drive object.
Set drvObject = fsoObject.GetDrive("\\PublicDocs")
' Check to see if the drive is ready.
If drvObject.IsReady Then
' Drive is ready for read/write.
Else
' Drive is not ready.
End If
|
|
| メモ | |
|
何らかのドライブアクセスを試行する前に、IsReady プロパティを使用することをお勧めします。このプロパティは、リムーバブルメディアドライブ (フロッピードライブと CD-ROM ドライブ) および固定メディアドライブの準備できているかどうかを判別できます。 |
|
| IsRootFolder (Folder オブジェクト) | |
| fdr.IsRootFolder | |
|
現在のフォルダがルートフォルダかどうかを判断できるブール値です。これは読み取り専用のプロパティです。 |
|
| パラメータ | |
|
なし |
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim fdrObject ' Folder Object
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFolder method of fsoObject, initialize a
' File object.
Set fdrObject = fsoObject.GetFolder("PublicDocs.txt")
' Determine whether the current folder is a root folder
' or if it is nested.
If fdrObject.IsRootFolder Then
' Folder is located directly off the drive letter
' or share name.
Else
' The folder is nested within at least one other
' folder.
End If
|
|
| メモ | |
|
Microsoft のマニュアルには、このプロパティを使用して現在のフォルダがネストされているレベル数を判別する方法について記載されています。便宜的に、この方法を次のコードで示します。 <%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim fdrObject ' Folder Object
Dim intNestedLevel ' Level to which the folder is nested
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFolder method of fsoObject, initialize a
' File object.
Set fdrObject = fsoObject.GetFolder("PublicDocs.txt")
' Determine whether the current folder is a root folder
' or if it is nested.
If fdrObject.IsRootFolder Then
' Folder is located directly off the drive letter or
' share name.
Else
' For more on the ParentFolder property of the
' Folder object, see the following.
Do Until fdrObject.IsRootFolder
Set fdrObject = fdrObject.ParentFolder
intNestedLevel = intNestedLevel + 1
Loop
End If
|
|
| ParentFolder (File オブジェクト、Folder オブジェクト) | |
| Obj.ParentFolder | |
|
ファイルまたはフォルダが置かれているフォルダを表す Folder オブジェクトを返します。これは読み取り専用のプロパティです。 |
|
| パラメータ | |
|
なし |
|
| 例 | |
|
次のコードは、最初に File オブジェクトで、次に Folder オブジェクトで使用する際の ParentFolder プロパティの使用方法を示します。Name は Folder オブジェクトのデフォルトのプロパティであるため、ASP ページ内のコードは、ParentFolder プロパティが返す値を文字列として処理することになります。 <%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim filObject ' File Object
Dim fdrObject ' Folder Object
Dim strFileParent ' Parent folder of file object
Dim strFolderParent ' Parent folder of folder object
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFile method of fsoObject, initialize the
' File object.
Set filObject = fsoObject.GetFile("d:\docs\test.txt")
' Retrieve the name of the folder containing the file Test.TXT.
' In this example, the value of strFileParent is "docs".
strFileParent = filObject.ParentFolder
' Using the GetFolder method of fsoObject, initialize
' the Folder object.
Set fdrObject = fsoObject.GetFolder("d:\mystuff\docs")
' Retrieve the name of the folder that contains the
' folder "docs". In this example, the value of
' strFileParent is "mystuff".
strFolderParent = fdrObject.ParentFolder
|
|
| Close (TextStream オブジェクト) | |
| tsObj.Close | |
|
TextStream オブジェクトとして開かれたテキストファイルを閉じます。 |
|
| パラメータ | |
|
なし |
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim tsObject ' TextStream Object
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the OpenTextFile method of fsoObject, initialize
' the File object.
Set tsObject = fsoObject.OpenTextFile( _
"d:\docs\test.txt", ForReading, False)
' Read into the string the contents of the text file.
strContents = tsObject.ReadAll
' Close the open text file.
tsObject.Close
|
|
| メモ | |
|
Visual Basic での開いているファイルの使用方法と同様に、アプリケーションで許されるオープンファイル数は限られているため、処理が終了したら開いているテキストファイルをすべて閉じることが重要です。 |
|
| Copy (File オブジェクト、Folder オブジェクト) | |
| obj.Copy strDestination [, blnOverWrite] | |
|
ファイルをある場所から別の場所へコピーします。 |
|
| パラメータ | |
|
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim filObject ' File Object
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFile method of fsoObject, initialize
' the File object.
Set filObject = fsoObject.GetFile("d:\docs\test.txt")
' Copy the file to a temporary directory.
filObject.Copy "e:\storage\temp\test_copy.txt", True
|
|
| メモ | |
|
Copy メソッドは、FileSystemObject オブジェクトの CopyFile メソッドや CopyFolder メソッドとまったく同じ機能を実行します。ただし、CopyFile メソッドと CopyFolder メソッドでは、複数のファイルやフォルダを一度にコピーできることに注意する必要があります。 |
|
| CopyFolder (FileSystemObject オブジェクト) | |
| fsoObj.CopyFolder strSource, strDestination [, blnOverWrite] | |
|
フォルダとそのすべてのコンテンツをある場所から別の場所へコピーできます。 |
|
| パラメータ | |
|
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Use the FileSystemObject object's CopyFolder method
' to copy the Temp directory and all its contents from
' the C drive to the D drive, overwriting if necessary.
fsoObject.CopyFolder "c:\temp", "d:\temp", True
|
|
| メモ | |
|
CopyFolder の呼び出しでエラーが発生すると、このメソッドはすぐに停止し、既に実行済みのアクションを元に戻すことはしません。 CopyFolder メソッドの速さは、コマンド行によるフォルダのコピーと同程度の速さです。 |
|
| CreateFolder (FileSystemObject オブジェクト) | |
| fsoObj.CreateFolder( strFolderName) | |
|
フォルダを指定された場所に作成します。 |
|
| パラメータ | |
|
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Create a new directory.
fsoObject.CreateFolder("e:\storage\newdir")
|
|
| メモ | |
|
既に存在しているフォルダを作成しようとすると、エラーが発生します。 |
|
| Delete (File オブジェクト、Folder オブジェクト) | |
| Obj.Delete blnForce | |
|
ファイルまたはフォルダを削除します。 |
|
| パラメータ | |
|
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim filObject ' File Object
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFile method of fsoObject, initialize the
' File object.
Set filObject = fsoObject.GetFile("d:\docs\test.txt")
' Delete the TEST.TXT file--even if the file is marked
' as read-only.
filObject.Delete True
|
|
| メモ | |
|
File オブジェクトと Folder オブジェクトの Delete メソッドは、FileSystemObject オブジェクトの DeleteFile メソッドおよび DeleteFolder メソッドと機能的には同じです。Folder オブジェクトの Delete メソッドを使用すると、該当するフォルダとそのすべてのコンテンツが削除されます。このメソッドは、ファイルを含むディレクトリを削除しようとしても警告を出しません。 |
|
| GetBaseName (FileSystemObject オブジェクト) | |
| fsoObj.GetBaseName( strPath) | |
|
完全ファイルパスから "ファイル拡張子を除いた" ファイル名を抽出します。 |
|
| パラメータ | |
|
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetBaseName method, retrieve the base
' names of several path strings.
' This example returns "searchstart" as the base name.
Response.Write fsoObject.GetBaseName( _
"/apps/search/searchstart.asp")
' This example returns "search" as the base name.
Response.Write fsoObject.GetBaseName("/apps/search/")
' This example returns "search" as the base name.
Response.Write fsoObject.GetBaseName("/apps/search")
' This example returns "nofile" as the base name--even
' though the nofile.txt file does not exist.
fsoObject.GetBaseName("/apps/search/nofile.txt")
|
|
| メモ | |
|
GetBaseName は、パス文字列からファイルの基本名の取得を試みます。パス文字列の最後の要素がフォルダである場合、閉じるスラッシュ (/) またはバックスラッシュ (\) 文字を指定しても、フォルダ名が返されます。パス文字列は、サーバー上の実際のパスとしてその有効性と存在がチェックされることはありません。このメソッドは、パスを文字列とみなすだけです。このため、このメソッドと FileSystemObject オブジェクトとを関連付けることは、ファイル操作が実際に行われないため誤解を生みます。 |
|
| GetParentFolderName (FileSystemObject オブジェクト) | |
| fsoObj.GetFolderName ( strPath) | |
|
指定されたパス文字列内の最後の親フォルダの名前を判別します。 |
|
| パラメータ | |
|
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject(
"Scripting.FileSystemObject")
' Using the GetParentFolderName method, retrieve the
' parent folder names of several path strings.
' This example returns "search" as the parent folder
' name.
Response.Write fsoObject.GetParentFolderName( _
"/apps/search/searchstart.asp")
' This example return "apps" as the parent folder name
Response.Write fsoObject.GetParentFolderName ("/apps/search/")
' This example also returns "apps" as the parent folder
' name.
Response.Write fsoObject.GetParentFolderName ("/apps/search")
' This example returns "nofile" as the parent folder
' name--even though nofile.txt does not exist.
Response.Write fsoObject.GetParentFolderName( _
"/apps/search/nofile.txt")
|
|
| メモ | |
|
FileSystemObject オブジェクトの GetBaseName メソッドと同様に、GetParentFolderName メソッドはパス文字列自身でのみ動作します。パス文字列パラメータの有効性と存在がチェックされることはありません。 |
|
| GetSpecialFolder (FileSystemObject オブジェクト) | |||||||||||||
| fsoObj.GetSpecialFolder (intSpecialFolderType) | |||||||||||||
|
Web サーバー上の特別なフォルダの完全物理パスを取得します。 |
|||||||||||||
| パラメータ | |||||||||||||
|
|||||||||||||
| 例 | |||||||||||||
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
' Declare file constants.
Const WindowsFolder = 0
Const SystemFolder = 1
Const TemporaryFolder = 2
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Use GetSpecialFolder to retrieve the physical path
' for the Windows, System, and Temp directories.
' This example returns something similar to "C:\WINNT".
fsoObject.GetSpecialFolder(WindowsFolder)
' This example returns something similar to
' "C:\WINNT\SYSTEM32".
fsoObject.GetSpecialFolder(SystemFolder)
' This example returns something similar to
' "C:\WINNT\TEMP"
fsoObject.GetSpecialFolder(TemporaryFolder)
|
|||||||||||||
| メモ | |||||||||||||
|
ファイルアクセスコンポーネントで使用する定数は、明示的に宣言する必要があります。 |
|||||||||||||
| MoveFolder (FileSystemObject オブジェクト) | |
| fsoObj.MoveFolder strSourcePath, strDestinationPath | |
|
フォルダとそのすべてのコンテンツをある場所から別の場所へ移動します。 |
|
| パラメータ | |
|
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the MoveFolder method, move all the folders
' under C:\APPS to the D: drive.
fsoObject.MoveFolder "C:\APPS\*.*", "D:\"
|
|
| メモ | |
|
フォルダを既にファイル名となっている宛先に移動しようとすると、エラーが発生します。指定する宛先が既存のフォルダの名前を表している場合、ソースパラメータがワイルドカードまたはバックスラッシュ (\) で終了していない限り、エラーが発生します。この場合、ソースフォルダとそのすべてのコンテンツは、宛先フォルダに移動されます。たとえば、次のコードではエラーが発生します。 <% ' Assume FileSystemObject object is instantiated 'already. Also assume that D:\ apps already exists. fsoObject.MoveFolder "C:\apps", "d:\apps" %> 一方、次のコードではエラーは発生しません。 <% ' Assume FileSystemObject object is instantiated ' already. Also assume that D:\ apps already exists. fsoObject.MoveFolder "C:\apps\*.*", "d:\apps" ' This last line create an apps folder in the D:\apps ' folder (making D:\apps\apps) %> MoveFolder の呼び出し時に Web サーバーでエラーが発生した場合、すべてのアクションが停止します。前のアクションのロールバックは行われません。たとえば、3 つの一連のフォルダをそのすべてのコンテンツと共に移動しようとして、移動対象の 3 番目のフォルダでエラーが発生した場合、3 番目のフォルダが移動されていない状態でも、最初の 2 つのフォルダは移動されたままの状態になります。実際に移動されたファイルやフォルダ、および移動されていないファイルやフォルダをチェックするには、独自のコードを指定する必要があります。 ボリューム間でフォルダを移動する場合、基になるオペレーティングシステムがこの操作をサポートし、Web サーバー上のユーザーセキュリティでこの操作を許容する必要があります。 |
|
| OpenAsTextStream (File オブジェクト) | |||||||||||||||||||||||||
| tsObject =filObj.OpenAsTextStream [ intAccessMode][, intFormat] | |||||||||||||||||||||||||
|
ファイルを開き、テキストファイルの読み取りまたは変更を行える TextStream オブジェクトを作成します。このメソッドは TextStream オブジェクトを返します。 |
|||||||||||||||||||||||||
| パラメータ | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| 例 | |||||||||||||||||||||||||
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim filObject ' File Object
Dim tsObject ' TextStream object
' Declare File Access constants.
Const ForAppending = 8
Const TristateTrue = -1
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFile method of fsoObject, initialize the
' File object.
Set filObject = fsoObject.GetFile("d:\docs\test.txt")
' Use the OpenAsTextStream method to open the file for
' appending and in Unicode format.
Set tsObject = filObject.OpenAsTextStream(ForAppending, TristateTrue)
%>
|
|||||||||||||||||||||||||
| メモ | |||||||||||||||||||||||||
|
OpenAsTextStream メソッドは、実際上は FileSystemObject オブジェクトの OpenTextFile メソッドに相当します。唯一の違いは、OpenAsTextStream メソッドではまた、ファイルが存在していない場合に、新しいテキストファイルを作成できることです。 ファイルアクセスコンポーネントで使用する定数は、明示的に宣言する必要があります。 |
|||||||||||||||||||||||||
| ReadLine (TextStream オブジェクト) | |
| tsObj.ReadLine | |
|
ReadLine メソッドは、テキストファイルから文字列変数への読み込み、またはこのような読み込みの結果と他のエンティティとの比較が可能という点で、TextStream オブジェクトの Read メソッドに似ています。ただし、パラメータを使用して読み取り文字数を判断する Read メソッドとは異なり、ReadLine メソッドは、現在のポインタ位置から次の改行文字までのすべての文字を読み取ります。 |
|
| パラメータ | |
|
なし |
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim filObject ' File Object
Dim tsObject ' TextStream object
Dim strBuffer ' Holding buffer
' Declare file access constants.
Const ForReading = 1
Const TristateFalse = 0
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFile method of fsoObject, initialize the
' File object.
Set filObject = fsoObject.GetFile("d:\docs\test.txt")
' Use the OpenAsTextStream method to open the file for
' reading and in ASCII format.
Set tsObject = filObject.OpenAsTextStream(ForReading, TristateFalse)
' Use the ReadLine method to read the next line of text
' from the text file into the strBuffer variable.
strBuffer = tsObject.ReadLine
%>
|
|
| メモ | |
|
ReadLine メソッドの呼び出し後、ファイル内のポインタの現在の位置は、最後の改行文字の直後、またはファイルマーカーの最後に置かれます。 ファイルアクセスコンポーネントで使用する定数は、明示的に宣言する必要があります。 |
|
| Write (TextStream オブジェクト) | |
| tsObj.Write(strWriteString) | |
|
開いているテキストファイルのファイルポインタの現在の位置に、指定された文字列を書き込みます。 |
|
| パラメータ | |
|
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim filObject ' File Object
Dim tsObject ' TextStream object
Dim strEnding
' Declare file access constants.
Const ForAppending = 8
Const TristateFalse = 0
' Initialize string variable. This string will be
' written to the end of the file opened next.
strEnding = "This is the end, my only friend, the end..."
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFile method of fsoObject, initialize the
' File object.
Set filObject = fsoObject.GetFile("d:\docs\test.txt")
' Use the OpenAsTextStream method to open the file for
' appending and in Unicode format.
Set tsObject = filObject.OpenAsTextStream(ForAppending, TristateFalse)
' Write a short string to the end of the opened file.
tsObject.Write strEnding
|
|
| メモ | |
|
Write メソッドは、書き込まれる各文字列の先頭または末尾に何の文字も配置しません。このため、Write メソッドを使用してファイルに追加する場合、目的の文字 (空白、改行文字など) をファイルに書き込む文字列の先頭または末尾に指定してください。 |
|
| WriteLine (TextStream オブジェクト) | |
| tsObj.WriteLine([strWriteString]) | |
|
文字列をオープンファイルのファイル内のポインタの位置に書き込みます。このメソッドはまた、改行文字を追加される文字列の末尾に書き込みます。それ以外は、Write メソッドとまったく同じです。
|
|
| 例 | |
<%
' Dimension local variables.
Dim fsoObject ' FileSystemObject
Dim filObject ' File Object
Dim tsObject ' TextStream object
Dim strEnding
' Declare file access constants.
Const ForAppending = 8
Const TristateFalse = 0
' Initialize a string variable that will be written to
' the end of the file opened next.
strEnding = "This is the end, my only friend, the end..."
' Instantiate the FileSystemObject variable.
Set fsoObject = Server.CreateObject( _
"Scripting.FileSystemObject")
' Using the GetFile method of fsoObject, initialize the
' File object.
Set filObject = fsoObject.GetFile("d:\docs\test.txt")
' Use the OpenAsTextStream method to open the file for
' appending and in Unicode format.
Set tsObject = filObject.OpenAsTextStream(ForAppending, TristateFalse)
' Write a short string plus a newline character to the
' end of the opened file.
tsObject.WriteLine strEnding
|
|
| メモ | |
|
WriteLine メソッドの呼び出し後、ファイルポインタは、ファイルに追加された改行文字の直後に置かれている文字をポイントします。 |
|