|
|
テクニカルノート02: ファイルシステムへのアクセスMarch 12, 2003© NSB Corporation. All rights reserved. |
このコントールの詳細は、マイクロソフト社のドキュメントを参照して下さい。
Fileオブジェクトを使用すると、NS Basic/CEからファイルシステムを制御できます。ファイルシステムオブジェクトの作成は、次のステートメントを使用します。
このオブジェクトに関する追加資料は、MicrosoftのWebサイトにて入手可能です。
addObject "filesystem"[,"file control name as string"]
2つ目の引数はオプションで、オブジェクトを参照する名前が指定できます。指定しない場合は、"File"を使います。本ドキュメントの最後に、ファイルオブジェクトを使ったサンプルコードがあります。
|
タイプ |
メソッド |
説明 |
| フォルダ |
|
一致するファイルまたはディレクトリ(フォルダ)の名前を返す。 |
|
|
|
新しいディレクトリ(フォルダ)の作成。 |
|
|
|
現在あるディレクトリ(フォルダ)を取除く。 |
| ファイル |
|
ファイルを移動。 |
|
|
|
ファイルをコピー。 |
|
|
|
ファイルに記された日時を返す。 |
|
|
|
ファイルの長さをバイト値で返す。 |
|
|
|
ディスクからファイルを削除。 |
| 属性 |
|
ファイル、ディレクトリ、またはフォルダの属性を返す。 |
|
|
|
ファイルに属性インフォメーションを設定。 |
REM This program demonstrates the use of the File and Filesystem Controls
Option Explicit
Dim selection
addObject "filesystem"
addObject "file"
selection=0
while selection<>9
selection=inputbox("Choose test number:" & chr(13) & "1. Attr" & chr(13) & "2. Dir" & chr(13) & "3. Get/Put" & chr(13) & "4. Line Write" & chr(13) & "5. Write/Read" & chr(13) & "9. End Program", "File System Demo")
select case selection
case 1
cmdAttr_click
case 2
cmdDir_click
case 3
cmdGetPut_click
case 4
cmdLineWrite_click
case 5
cmdWrite_click
case else
selection=9
end select
wEnd
Private Sub cmdAttr_Click()
On Error Resume Next
Dim sTheFile
sTheFile = inputBox("Enter file name:","ATTR Command")
msgbox "GetAttr:" & fileSystem.GetAttr(sTheFile) & chr(13) & "FileDateTime:" & fileSystem.FileDateTime(sTheFile) & chr(13) & "FileLen:" & fileSystem.fileLen(sTheFile),0,"File Attributes for " & sTheFile
If Err <> 0 Then
MsgBox "Error in GetAttr: " & Err.Description
Err.Clear
End If
End Sub
Private Sub cmdDir_Click()
Dim sDir, sMsg, input
input = inputBox("Enter file name (wildcards OK)","DIR Command")
sDir = filesystem.dir(input)
sMsg = "Directory contents of " & input & ": " & vbCrLf & sDir
While (sDir <> "")
sDir = fileSystem.Dir()
If sDir <> "" Then
sMsg = sMsg & ", " & sDir
End If
Wend
msgbox sMsg
End Sub
Private Sub cmdGetPut_Click()
WriteUsingPut
ReadUsingGet
End Sub
Private Sub cmdLineWrite_Click()
Writeline
Readline
End Sub
Private Sub cmdWrite_Click()
WriteUsingControl
ReadUsingControl
End Sub
Sub WriteUsingPut()
On Error Resume Next
Dim myArray
ReDim myArray(6)
file.Open "ceGetPut.txt", 4, 2, 3, 500 'fsAccessWrite
myArray(1) = 1
myArray(2) = "This is a string"
myArray(3) = True
myArray(4) = Date
myArray(5) = 63.12
file.Put myArray
If Err <> 0 Then
MsgBox "Error in WriteUsingPut: " & Err.Description
err.clear
End If
myArray(1) = 2
myArray(2) = "This is a string2"
myArray(3) = True
myArray(4) = Date + 1
myArray(5) = 63.12
file.Put myArray
myArray(1) = 3
myArray(2) = "This is a string3"
myArray(3) = True
myArray(4) = #11/16/34#
myArray(5) = 63.12
file.Put myArray
msgbox "done with Put", 0, "Put"
file.Close
End Sub
Sub ReadUsingGet()
Dim myArray,i,msgString
On Error Resume Next
file.Open "ceGetPut.txt", 4, 1, 3, 500
file.Get myArray, 2
msgString = myArray(1)
For i = 2 To UBound(myArray)
msgString = msgString & ", " & myArray(i)
Next
msgBox msgString,0,"Contents of ceGetPut.txt"
file.Close
End Sub
Sub WriteUsingControl()
Dim myArray
ReDim myArray(10)
myArray(1) = Date
myArray(2) = "This is a string with a "" (quote)."
myArray(3) = True
myArray(4) = #11/16/34#
myArray(5) = 63.12
myArray(6) = "Text"
myArray(7) = Null
myArray(8) = ""
file.Open "ceWrite.txt", 2 'fsModeOutput
file.WriteFields myArray
file.Close
End Sub
Sub ReadUsingControl()
Dim myArray, msgString, i
file.Open "ceWrite.txt", 1 'fsModeInput
myArray = file.InputFields(10)
msgString = myArray(1)
For i = 2 To UBound(myArray, 1)
msgString = msgString & ", " & myArray(i)
Next
msgbox msgString,0,"Contents of ceWrite.txt"
file.Close
End Sub
Sub Writeline()
On Error Resume Next
file.Open "ceLine.txt", 2 'fsModeOutput
If Err <> 0 Then
MsgBox "Error in writeline: " & Err.Description
Err.Clear
End If
file.LinePrint "Hier ist unser erste Linie."
file.LinePrint "Hier ist unser zweite Linie."
file.Close
End Sub
Sub Readline()
file.Open "ceLine.txt", 1 'fsModeInput
dim sOut
sOut = file.LineInputString()
sOut =sOut & Chr(13) & file.LineInputString()
msgBox sOut,0,"Contents of ceLine.txt"
file.Close
End Sub