20-2 ????

ڭ̤]iHϥ FileSystemObject GetFolder() kAXؿAMC|ؿݩʡCҦpG

Example]fileAccess/dirProp01.asp^G

dҪlXpUG

lɡ]fileAccess/dirProp01.asp^G]ǦϰUYi^
<%@language=JScript%>
<% title="CXؿݩ" %>
<!--#include file="../head.inc"-->
<hr>

<%
fso = Server.CreateObject("Scripting.FileSystemObject");
fileName = Request.ServerVariables("SCRIPT_NAME");
absPath = Server.MapPath(fileName);
parentDir = fso.GetParentFolderName(absPath);
dir = fso.GetFolder(parentDir);
methods = [
	"Attributes",
	"DateCreated",
	"DateLastAccessed",
	"DateLastModified",
	"Drive",
	"IsRootFolder",
	"Name",
	"ParentFolder",
	"Path",
	"ShortName",
	"ShortPath",
	"Size",
//	"SubFolders",
	"Type"];
%>
<h3 align=center>dir = <%=dir%></h3>
<table border=1 align=center>
<% for (i=0; i<methods.length; i++){
	cmd = "dir." + methods[i]; %>
	<tr><td><%=cmd%><td>&nbsp;<font color=green><%=eval(cmd)%></font>
<%}%>
</table>

<hr>
<!--#include file="../foot.inc"-->

t~bYDZpUAڭ̧Ʊ}ؿsvAϥΪ̬ݨؿتɮצW١Ao]iH ASP {XӹFCƹWAu}ؿsvv\ig Web A޲ztΨӹFAOnק惡ﶵAA㦳 Administrator vCڭ̪dҬOϥ ASP {XӹF\A]ݭnקA]wCШdҡG

Example]fileAccess/fileList01.asp^G

dҪlXpUG

lɡ]fileAccess/fileList01.asp^G]ǦϰUYi^
<%@language=JScript%>
<% title="CXؿe" %>
<!--#include file="../head.inc"-->
<hr>

<%
fso = Server.CreateObject("Scripting.FileSystemObject");
fullPath = Server.MapPath(".");
fd = fso.GetFolder(fullPath);
%>

<h3 align=center>
Contents of <%=fullPath%>:
</h3>
<table border=1 align=center>
<tr>
<th colspan=3>File Listing</th>
<tr>
<th>File name</th><th>Size (Bytes)</th><th>Last modified</th>
<%
var fileList=new Enumerator(fd.files);
for (fileList.moveFirst(); !fileList.atEnd(); fileList.moveNext()){
	Response.Write("<tr align=center>");
	Response.Write("<td><a href=\"" + fileList.item().name + "\">" + fileList.item().name + "</a></td>");
	Response.Write("<td>" + fileList.item().size + "</td>");
	Response.Write("<td>" + fileList.item().DateLastModified + "</td>");
	Response.Write("</tr>");
}
%>
</table>
<br>
<table border=1 align=center>
<tr>
<th colspan=3>Directory Listing</th>
<tr>
<tr>
<th>Folder name</th><th>Size (Bytes)</th><th>Last modified</th>
<%
var dirList=new Enumerator(fd.SubFolders);
for (dirList.moveFirst(); !dirList.atEnd(); dirList.moveNext()){
	Response.Write("<tr align=center>");
	Response.Write("<td><a href=\"" + dirList.item().name + "\">" + dirList.item().name + "</a></td>");
	Response.Write("<td>" + dirList.item().size + "</td>");
	Response.Write("<td>" + dirList.item().DateLastModified + "</td>");
	Response.Write("</tr>");
}
%>
</table>

<hr>
<!--#include file="../foot.inc"-->

YbAw]ɮ׬ؿDAhϥΪ̳sؿɡA|۰ʶ}ҦɮסAϥΪ̴N|ݨҦؿeCC

Lɮ׻PؿBz\AiqLnq޳NdơCڭ̥iHإߤΧRؿAidҡG

Example]fileAccess/folderCreate01.asp^G

dҪlXpUG

lɡ]fileAccess/folderCreate01.asp^G]ǦϰUYi^
<%@language=JScript%>
<% title="إ߻PRؿ" %>
<!--#include file="../head.inc"-->
<hr>

<%
// oFileSystemObjectC
fso = new ActiveXObject("Scripting.FileSystemObject");
// oDrive C
fldr = fso.GetFolder("c:");
// CLw]ƧW١C
Response.Write("w]ƧW٬OG" + fldr + "<br>");
// CLϺЦW١C
Response.Write("ϺоW١G" + fldr.Drive + "<br>");
// CLɮצW١C
if (fldr.IsRootFolder)
	Response.Write("oOڥؿI");
else
	Response.Write("oOڥؿI");

Response.Write("<br><br>");
// إߤ@ӸƧ 
fso.CreateFolder ("C:\\Bogus");
Response.Write("إ߸ƧGC:\\Bogus" + "<br>");
// CLƧ򩳦W١C
Response.Write("Basename = " + fso.GetBaseName("c:\\bogus") + "<br>");
// RƧC
fso.DeleteFolder ("C:\\Bogus");
Response.Write("RƧGC:\\Bogus" + "<br>");
%>

<hr>
<!--#include file="../foot.inc"-->

ڭ̥iHϥ GetSpecialFolder() 禡ӨίSؿA󤣦PJѼơA|^ǤPSؿACpUG

JѼƭ^ǥؿ
0Windows ƧA]t Windows @~tΩҦw˪ɮC:\WINDOWS
1System ƧA]t{wBrMg]Xʵ{C:\WINDOWS\system32
2ȦsƧAOΨxsȦsɡC|]b TMP ܼƤC:\WINDOWS\Temp

GetSpecialFolder() ϥνdҦpUG

Example]fileAccess/getSpecialFolder01.asp^G

dҪlXpUG

lɡ]fileAccess/getSpecialFolder01.asp^G]ǦϰUYi^
<%@language=JScript%>
<% title="oSؿ" %>
<!--#include file="../head.inc"-->
<hr>

<%
fso = new ActiveXObject("Scripting.FileSystemObject");
windowsFolder = fso.GetSpecialFolder(0);	// Windows Ƨ
systemFolder = fso.GetSpecialFolder(1);		// System Ƨ
temporaryFolder = fso.GetSpecialFolder(2);	// ȦsƧ
Response.Write("windowdsFolder = " + windowsFolder.Path + "<br>");
Response.Write("systemFolder = " + systemFolder.Path + "<br>");
Response.Write("temporaryFolder = " + temporaryFolder.Path + "<br>");
%>

<hr>
<!--#include file="../foot.inc"-->

ѮɭԦb{BzL{AݭngJ@ӼȦsɮסAɧڭ̴NiHϥ GetSpecialFolder(2) Өotιw]ȦsƧAå GetTempName() ӨoȦsɮצW١AidҡG

Example]fileAccess/getSpecialFolder02.asp^G

AsJɡAN|oıCȦsɮצWٳ|PA]|\즳ɮצW١CAiH즹dҺҦLXȦsɮ׸|AݬݦɮפeO_uHello WorldvCdҪlXpUG

lɡ]fileAccess/getSpecialFolder02.asp^G]ǦϰUYi^
<%@language=JScript%>
<% title="gJȦsɮ" %>
<!--#include file="../head.inc"-->
<hr>

<%
fso = new ActiveXObject("Scripting.FileSystemObject");
tempFile = fso.GetTempName();
Response.Write("ȦsɮצW = " + tempFile + "<br>");
tempDir = fso.GetSpecialFolder(2);
Response.Write("Ȧsɮ׸| = " + tempDir.Path + "\\" + tempFile + "<br>");
fid = tempDir.CreateTextFile(tempFile);
fid.writeline("Hello World");
fid.close();
Response.Write("ڭ̤wgbȦsɮ׼gJ \"Hello World\"I<br>");
%>

<hr>
<!--#include file="../foot.inc"-->


JScript {]pPΡGΩAݪ ASP