FSOは、Microsoft ASPのファイル操作のコントロールです。そのため、間違った新しいチャネルの編集者がFSOコードの詳細な分析を共有します。
FSOを使用してファイル固有のコンテンツを変更する関数
functionfsochange(ファイル名、ターゲット、文字列)
dimobjfso、objcountfile、filetempdata
setobjfso = server.createObject( "Scripting.filesystemObject")
setobjcountfile = objfso.opentextfile(server.mappath(filename)、1、true)
filetempdata = objcountfile.readall
objcountfile.close
filetempdata =置換(filetempdata、ターゲット、文字列)
setobjcountfile = objfso.createTextfile(server.mappath(filename)、true)
objcountfile.writefiletempdata
objcountfile.close
setobjcountfile = Nothing
setobjfso =何もない
エンド機能
FSOを使用してファイルコンテンツを読み取る関数
functionfsofileread(filename)
dimobjfso、objcountfile、filetempdata
setobjfso = server.createObject( "Scripting.filesystemObject")
setobjcountfile = objfso.opentextfile(server.mappath(filename)、1、true)
fsofileread = objcountfile.readall
objcountfile.close
setobjcountfile = Nothing
setobjfso =何もない
エンド機能
FSOを使用してファイルの行を読み取る関数
functionfsolinedit(filename、linenum)
iflinenum
dimfso、f、temparray、tempcnt
setFSO = server.createObject( "Scripting.filesystemObject")
ifnotfso.fileexists(server.mappath(filename))thenexitfunction
setf = fso.opentextfile(server.mappath(filename)、1)
ifnotf.atendofstreamthen
tempcnt = f.readall
f.close
setf = Nothing
テンプレート= split(tempcnt、chr(13)&chr(10))
iflinenum> ubund(temparray)+1then
exitFunction
それ以外
fsolinedit = temparray(linenum-1)
endif
endif
エンド機能
FSOを使用してファイルの特定の行を書き込む機能
functionfsolinewrite(filename、linenum、linecontent)
iflinenum
dimfso、f、temparray、tempcnt
setFSO = server.createObject( "Scripting.filesystemObject")
ifnotfso.fileexists(server.mappath(filename))thenexitfunction
setf = fso.opentextfile(server.mappath(filename)、1)
ifnotf.atendofstreamthen
tempcnt = f.readall
f.close
テンプレート= split(tempcnt、chr(13)&chr(10))
iflinenum> ubund(temparray)+1then
exitFunction
それ以外
テンプレート(linenum-1)= linecontent
endif
tempcnt = join(temparray、chr(13)&chr(10))
setf = fso.createTextfile(server.mappath(filename)、true)
f.writeTempcnt
endif
f.close
setf = Nothing
エンド機能
FSOを使用してファイルの新しい行を追加する機能
functionfsoappline(filename、linecontent)
dimfso、f
setFSO = server.createObject( "Scripting.filesystemObject")
ifnotfso.fileexists(server.mappath(filename))thenexitfunction
setf = fso.opentextfile(server.mappath(filename)、8,1)
f.writechr(13)&chr(10)&linecontent
f.close
setf = Nothing
エンド機能
ファイルの最後の行を読み取る関数
functionfsolastline(filename)
dimfso、f、temparray、tempcnt
setFSO = server.createObject( "Scripting.filesystemObject")
ifnotfso.fileexists(server.mappath(filename))thenexitfunction
setf = fso.opentextfile(server.mappath(filename)、1)
ifnotf.atendofstreamthen
tempcnt = f.readall
f.close
setf = Nothing
テンプレート= split(tempcnt、chr(13)&chr(10))
fsolastline = temparray(ubund(temparray))
endif
エンド機能
FSOは、指定されたファイルの文字を置き換えます
プログラムコード:
'FSOは、指定されたファイルの文字を置き換えます
functionfsolineedit(filename、ターゲット、文字列)
dimobjfso、objcountfile、filetempdata
setobjfso = server.createObject( "Scripting.filesystemObject")
setobjcountfile = objfso.opentextfile(server.mappath(filename)、1、true)
filetempdata = objcountfile.readall
objcountfile.close
filetempdata =置換(filetempdata、ターゲット、文字列)
setobjcountfile = objfso.createTextfile(server.mappath(filename)、true)
objcountfile.writefiletempdata
objcountfile.close
setobjcountfile = Nothing
setobjfso =何もない
エンド機能
'Response.WriteFsolineEdit( "test.txt"、 "world"、 "明日は良い日です")
ファイルを削除します
プログラムコード:
'ファイルを削除します
functiondelfile(ファイル名)
iffilename "" then
setFSO = server.createObject( "Scripting.filesystemObject")
iffso.fileexists(filename)then
FSO.DELETEFILEFILENAME
endif
setfso =何もない
endif
エンド機能
ファイルが存在するかどうかを判断します
プログラムコード:
'ファイルが存在するかどうかを判断してください
functionReportFileStatus(fileSpec)
dimfso、msg
setFSO = createObject( "Scripting.filesystemObject")
if(fso.fileexists(filespec))then
msg = fileSpec& "Existes。"。
それ以外
msg = fileSpec& "Notexist。"。
endif
ReportFileStatus = MSG
エンド機能
FSOを使用してファイル固有のコンテンツを変更する関数
プログラムコード:
'FSOを使用して、ファイル固有のコンテンツ関数を変更します
functionfsochange(ファイル名、ターゲット、文字列)
dimobjfso、objcountfile、filetempdata
setobjfso = server.createObject( "Scripting.filesystemObject")
setobjcountfile = objfso.opentextfile(server.mappath(filename)、1、true)
filetempdata = objcountfile.readall
objcountfile.close
filetempdata =置換(filetempdata、ターゲット、文字列)
setobjcountfile = objfso.createTextfile(server.mappath(filename)、true)
objcountfile.writefiletempdata
objcountfile.close
setobjcountfile = Nothing
setobjfso =何もない
エンド機能
FSOを使用してファイルの特定の行を書き込む機能
プログラムコード:
'FSOを使用して、ファイルの特定の行を持つ関数を書き込む
functionfsolinewrite(filename、linenum、linecontent)
iflinenum
dimfso、f、temparray、tempcnt
setFSO = server.createObject( "Scripting.filesystemObject")
ifnotfso.fileexists(server.mappath(filename))thenexitfunction
setf = fso.opentextfile(server.mappath(filename)、1)
ifnotf.atendofstreamthen
tempcnt = f.readall
f.close
temparray = split(tempcnt、chr(13)&chr(10))
iflinenum> ubound(temparray)+1then
exitFunction
それ以外
テンプレート(linenum-1)= linecontent
endif
tempcnt = join(temparray、chr(13)&chr(10))
setf = fso.createTextfile(server.mappath(filename)、true)
f.writeTempcnt
endif
f.close
setf = Nothing
エンド機能
ディレクトリを作成するプログラム。ディレクトリに複数のレベルがある場合は、一度に1つのレベルを作成します。
プログラムコード:
'ディレクトリを作成するプログラム。ディレクトリに複数のレベルがある場合は、一度に1つのレベルを作成します。
functioncreatedir(byvallocalpath)
onerrorresumenext
localpath = cheplage(localpath、 "/"、 "/")
setFileObject = server.createObject( "Scripting.filesystemObject")
patharr = split(localpath、 "/")
path_level = ubound(patharr)
fori = 0topath_level
ifi = 0thenpathtmp = patharr(0)& "/" elsepathtmp = pathtmp&patharr(i)& "/"
cpath = left(pathtmp、len(pathtmp)-1)
ifnotfileobject.folderexists(cpath)thenfileobject.createfoldercpath
次
setFileObject = Nothing
iferr.number0then
createdir = false
err.clear
それ以外
createdir = true
endif
エンド機能
これらの不動のいくつかのいくつかはありますが、非常にクールな機能を紹介します。
めったに理解されないFSO機能
GetSepecialFolderMethod特定のWindowsフォルダーのパスを返します。Windowsインストールディレクトリ。 Windowsシステムディレクトリ。 Windows一時ディレクトリFSO.getSpecialFolder([0,1、OR2])
getTemPnameMethodランダムに生成されたファイルまたはディレクトリ名を返します。これは、一時データが必要なときに使用されます。
getabsolutepathnamemethodフォルダーへの絶対パスを返します(server.mappathに似ています)。
たとえば、fso.getabsolutepathName( "region")は、次のような結果を返します。「C:mydocsmyfolderegion」
getExtensionNameMethodパスの最後の部分の拡張を返します
(例:fso.getExtensionName( "c:docsest.txt")txtを返します)
getBasENAMENDGETPARENTFOLDERMETHSSパスの最後の部分の親フォルダーを返します
(例:fso.getParentFolder( "c:docsmydocs")は「docs」を返します)
DrivesPropertyは、リソースブラウザーのようなユーザーインターフェイスを構築するために、ローカルで利用可能なすべてのドライブのコレクションを返します。
上記の関数を使用する場合、エラー処理用のコードを作成するのが最善です。必要なパラメーターが存在しない場合、面倒な情報が生成されるためです。
上記は、FSOコードの詳細な分析です。あなたはそれをすべて学んだと思います。関連するコンテンツについては、引き続きWuxin Technologyチャネルに注意を払います。