ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[±Ð¾Ç] (ASP±Ð¾Ç²Ä12½g) Àɮצs¨ú¤¸¥ó

[±Ð¾Ç] (ASP±Ð¾Ç²Ä12½g) Àɮצs¨ú¤¸¥ó

File Access ª«¥ó
File Access ¤¸¥ó¤¹³\ASPµ{¦¡¦s¨úºô­¶¦øªA¾¹¤WªºÀɮסA¹ê°È¤W¤j ³¡¥÷¥H¤å¦rÀɬ°¥D¡A¨Æ¹ê¤W¡AFile Access¤¸¥ó¬O¥ÑFileSystemObject ª«¥ó¤ÎTextStream ª«¥ó©Ò²Õ¦¨ªº¡C FileSystemObject ª«¥ó­t³d¶}±ÒÀɮשάO¥Ø¿ýªº³B¸Ì¡A¦ý­Y·QŪ¨ú Àɮפº®e¡A«h¥²¶·°t¦XTextStream ª«¥ó¤@°_¨Ï¥Î¡C File Access¤¸¥ó¤w¥]§t¦bIIS4.0¤¤¡A¦]¦¹¡A¤£»Ý­«·s¦w¸Ë¦¹¤¸¥ó´N¥iª½±µ¨Ï¥Î¡C »yªk¦p¤U©Ò¥Ü(fs ¬O§Ú­Ì¦Û­qªº¤@­Ó¤¸¥óÅܼƦW):
  1. set fs=server.CreateObject("Scripting.FileSystemObject")
½Æ»s¥N½X
¨Ò¦p¡G


ÀÉ®×¾Þ§@ªº¤èªk:
CopyFile ½Æ»sÀɮסA»yªk¦p¤U:
  1. FileSystemObject.copyfile source,destination[,overwrite]
½Æ»s¥N½X

  • source(¨Ó·½ÀÉ®×):¥²¶·¬O¤w¦s¦bªºÀɮסA§_«h·|²£¥Í¡y§ä¤£¨ì¨Ó ·½Àɮסzªº¿ù»~(err.numer=53)¡C
  • destination(¥ØªºÀÉ®×):ÀÉ®×­Y¤w¦s¦b¡A«h·|³QÂл\¡A­Y¬°°ßŪÄÝ ©Ê©Î³QÂê©wªºÀɮסA«h·|²£¥Í¡y¨S¦³¨Ï¥ÎÅv­­¡zªº¿ù»~(err .number=70)¡C  
  • overwrite(¬O§_Âл\):¹w³]­È¬°true¡Aªí¥Ü¦s¦bªºÀÉ®×±N³QÂл\¡C

½d¨Òµ{¦¡½X¦p¤U:
  1. <%
  2. set fs=server.createobject("scripting.filesystemobject")
  3. source=server.mappath("Count.txt")
  4. target=server.mappath("Count1.txt")

  5. on error resume next
  6. fs.copyfile source,target
  7. if err.number=53 then
  8.    response.write source & "Àɮפ£¦s¦b"
  9.    response.end
  10. elseif err.number=70 then
  11.    response.write target & "Àɮ׬°°ßŪÀɮשΤw³QÂê©w"
  12.    response.end
  13. seif err.number<>0 then
  14.    response.write "¨ä¥L¿ù»~,¿ù»~½s¸¹=" & err.number
  15.    response.end
  16. end if
  17. %>
½Æ»s¥N½X
DeleteFile:§R°£ÀɮסA»yªk¦p¤U
  1. FileSystemObject.Deletefile Filename[,Flag]
½Æ»s¥N½X

  • Filename(³Q§R°£ªºÀÉ®×):¥²¶·¬°¤w¦s¦bªºÀɮסA§_«h·|²£¥Í¡y§ä ¤£¨ì¨Ó·½ÀÉ¡zªº¿ù»~(err.number=53)¡C  
  • Flag(true or false):¹w³]­È¬°false¡Atrueªí¥i¥H§R°£°ßŪÄÝ©Ê ³]©wªºÀɮסA­Y¤£³]¬° true¡A«h¹J¨ì°ßŪÄÝ©ÊÀɮ׮ɱN²£ ¥Í¡y¨S¦³¨Ï¥ÎÅv­­¡zªº¿ù»~ (err.number=70)¡C

½d¨Òµ{¦¡½X¦p¤U:
  1. <%
  2. set fs=server.createobject("scripting.filesystemobject")
  3. source=server.mappath("Count.txt")
  4. target=server.mappath("Count1.txt")

  5. on error resume next
  6. fs.deletefile source,target
  7. if err.number=53 then
  8.    response.write source & "Àɮפ£¦s¦b"
  9.    response.end
  10. elseif err.number=70 then
  11.    response.write target & "Àɮ׬°°ßŪÀɮשΤw³QÂê©w"
  12.    response.end
  13. seif err.number<>0 then
  14.    response.write "¨ä¥L¿ù»~,¿ù»~½s¸¹=" & err.number
  15.    response.end
  16. end if
  17. %>
½Æ»s¥N½X
MoveFile ²¾°ÊÀɮשΧó¦W¡A»yªk¦p¤U:
  1. FileSystemObject.Movefile source,destination
½Æ»s¥N½X

  • Source(¨Ó·½ÀÉ®×):¥²¶·¬O¤w¦s¦bªºÀɮסA§_«h·|²£¥Í¡y§ä¤£¨ì¨Ó ·½ÀÉ¡zªº¿ù»~(err.numer=53)¡C
  • Destination(¥ØªºÀÉ®×):¥²¶·¬O¤£¦s¦bªºÀɮסA§_«h·|²£¥Í¡y ÀÉ ®×¤w¦s¦b¡zªº¿ù»~(err.number=58)¡C
  • ­Ysource»Pdestination ©Ò¦b¥Ø¿ý¬Û¦P¡A«h MoveFile¤§ ¥\¥Î¬O§ó¦W¡A­Y source»P destination©Ò¦b¥Ø¿ý¤£¦P¡A«hMoveFile¤§¥\¥Î¬O²¾°ÊÀɮסC

½d¨Òµ{¦¡½X¦p¤U:
  1. <%
  2. set fs=server.createobject("scripting.filesystemobject")
  3. source=server.mappath("Count.txt")
  4. target=server.mappath("Count1.txt")

  5. on error resume next
  6. fs.movefile source,target
  7. if err.number=53 then
  8.    response.write source & "Àɮפ£¦s¦b"
  9.    response.end
  10. elseif err.number=70 then
  11.    response.write target & "Àɮ׬°°ßŪÀɮשΤw³QÂê©w"
  12.    response.end
  13. seif err.number<>0 then
  14.    response.write "¨ä¥L¿ù»~,¿ù»~½s¸¹=" & err.number
  15.    response.end
  16. end if
  17. %>
½Æ»s¥N½X
FileExists ÀËÅçÀɮ׬O§_¦s¦b¡A»yªk¦p¤U:
  1. FileSystemObject.FileExists(Filename)
½Æ»s¥N½X
ÀÉ®×­Y¦s¦b¡A«h¶Ç¦^­È¬°true¡A§_«h¶Ç¦^false¡C
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TextStream ª«¥ó
TextStream ª«¥ó¬°FileSystemObject ª«¥óªº¤lª«¥ó¡A«Ø¥ßªº¤èªk¦³¨âºØ¡C
OpenTextFile ¶}±ÒÀÉ®×
  1. set fs=server.CreateObject("Scripting.FileSystemObject")
  2. set txt=fs.OpenTextFile(°Ñ¼Æ...)
½Æ»s¥N½X
¡@

OpenTextFile©Ò¶Çªº°Ñ¼Æ¦p¤U:  
  1. OpenTextFile(Filename[,IOmode[,Create]])
½Æ»s¥N½X
Filename(ÀɮצWºÙ)¡B IOmode(¶}±Ò¼Ò¦¡):¥i¥H¦³¤U¦C¤TºØ³]©w­È

³]©w­È

»¡©ú

¢°

¶}±Ò¦¨¬°ÅªªºÀÉ®×¹w³]­È¬°1

¢±

¶}±Ò¦¨°ß¼gªºÀÉ®×­ìÀɮפº®e·|³Q²M°£

¢·

¶}±Ò¦¨°ß¼gªºÀÉ®×­ìÀɮפº¦p«O¯d¸ê®Æ·|±qÀɮ׳̫᭱¼g¤J


Create(¬O§_¦Û°Ê«ØÀÉ):¹w³]¬°false¡Aªí¶}±ÒªºÀÉ®×¥²¶·¬O¤w¸g ¦s¦bªºÀɮסA­Y³]¦¨true¡A«h·í©Ò­n¶}±ÒªºÀɮפ£¦s¦b®É ¡AFileSystemObject·|¦Û°Ê«Ø¥ßÀɮסC ¨ä¤¤IOmode»PCreate°Ñ¼Æ¥i¬Ù²¤¡C


CreateTextFile «Ø¥ß·sÀÉ®×
  1. set fs=server.CreateObject("Scripting.FileSystemObject")
  2. set txt=fs.CreateTextFile(°Ñ¼Æ...)
½Æ»s¥N½X
¡@


CreateTextFile©Ò¶Çªº°Ñ¼Æ¦p¤U:
  1. CreateTextFile(Filename[,Overwrite])
½Æ»s¥N½X
OverWrite(¬O§_Âмg­ìÀÉ®×):»Ý«Ø¥ß¦bÀɮפw¦s¦bªº±¡ªp¤U¡A¦¹ °Ñ¼Æ¤~¦³®Ä¡C­Y³]¬° true(¹w³])¡A«h­ìÀÉ®×·|³QÂмg¡A­Y ³]¬°false¡A«h·|¥X²{¡yÀɮפw¦s¦b¡zªº¿ù»~¡C


Ū¨úÀɮתº¤èªk
ReadLine:±qÀɮפ¤Åª¨ú¤@¦æ¸ê®Æ¡A¦p¤U¨Ò:
8.png
  1. <%
  2. set fs=server.createobject("scripting.filesystemobject")
  3. file=server.mappath("Count.txt")
  4. set txt=fs.opentextfile(file,1,true)

  5. if not txt.atendofstream then
  6.    line=txt.readline
  7.    response.write line & "<br>"
  8. end if
  9. %>
½Æ»s¥N½X
Read(N):±qÀɮפ¤Åª¨úN­Ó¦ì¤¸²Õªº¸ê®Æ¡A¦p¤U¨Ò:
5.png
  1. <%
  2. set fs=server.createobject("scripting.filesystemobject")
  3. file=server.mappath("Count.txt")
  4. set txt=fs.opentextfile(file,1,true)

  5. if not txt.atendofstream then
  6.    n=txt.read(10)
  7.    response.write n
  8. end if
  9. %>
½Æ»s¥N½X
ReadAll:Ū¨úÀɮפ¤ªº©Ò¦³¸ê®Æ¡A¦p¤U¨Ò:
6.png
  1. <%
  2. set fs=server.createobject("scripting.filesystemobject")
  3. file=server.mappath("Count.txt")
  4. set txt=fs.opentextfile(file,1,true)

  5. if not txt.atendofstream then
  6.    all=txt.readall
  7.    alls=replase(all,vbcrlf,"<br>")
  8.    response.write alls
  9. end if
  10. %>
½Æ»s¥N½X
¼g¤JÀɮתº¤èªk
WriteLine:·|¦b¸ê®Æ«á¥[vbCrLf,¤~±N¸ê®Æ¼g¨ìÀɮפ¤¡C
Write:­ì­ì¥»¥»±N¸ê®Æ¼g¤JÀɮפ¤¡A¦p¤U¨Ò:
7.png
  1. <%
  2. set fs=server.createobject("scripting.filesystemobject")
  3. file=server.mappath("Count.txt")
  4. set txt=fs.opentextfile(file,2,true)
  5. txt.writeline var
  6. txt.write var
  7. %>
½Æ»s¥N½X
¤ß¦w¡A¥­¦w   
µoªí¥ô¦óµL·N¸qªº·PÁ©ÎÄé¤ô¤å³¹¤@«ß¬å,¬Ã±¤±b¸¹,½Ð¸Ô¾\ª©³W!!

TOP

        ÀR«ä¦Û¦b : ¨ü¤HÂI¤ô¤§®¦¡A¶··í´é¬u¥H³ø¡C
ªð¦^¦Cªí ¤W¤@¥DÃD