ASP FSO 파일 처리 함수 대전

13305 단어 ASPFSO문서 처리
직접 코드

<% 
'        
Function CreateFolder(strFolder)'        
  '                  
  Dim strTestFolder,objFSO 
  strTestFolder = Server.Mappath(strFolder) 
  Set objFSO = CreateObject("Scripting.FileSystemObject") 
  '          
  If not objFSO.FolderExists(strTestFolder) Then 
 '            
 objFSO.CreateFolder(strTestFolder) 
  End If 
 Set objFSO = Nothing 
End function 

'      
Function DelFolder(strFolder)'        
 strTestFolder = Server.Mappath(strFolder) 
 Set objFSO = CreateObject("Scripting.FileSystemObject") 
 '          
 If objFSO.FolderExists(strTestFolder) Then 
 objFSO.DeleteFolder(strTestFolder) 
 end if 
 Set objFSO = Nothing 
End function 

'       
Function Createtextfile(fileurl,filecontent)'                 
 Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 
 Set fout = objFSO.CreateTextFile(Server.MapPath(fileurl)) 
 fout.WriteLine filecontent 
 fout.close 
 Set objFSO = Nothing 
End Function 

'    (      ) 
Function Deltextfile(fileurl)'        
 Set objFSO = CreateObject("Scripting.FileSystemObject") 
 fileurl = Server.MapPath(fileurl) 
 if objFSO.FileExists(fileurl) then '         
  objFSO.DeleteFile(Server.mappath(fileurl)) 
 end if 
 Set objFSO = nothing 
End Function 

'               
Function Createimage(fileurl,imagecontent)'             
 Set objStream = Server.CreateObject("ADODB.Stream")  '  ADODB.Stream  ,   ADO 2.5     
 objStream.Type =1  '         
 objStream.Open 
 objstream.write imagecontent  '           
 objstream.SaveToFile server.mappath(fileurl),2  '-           
 objstream.Close()'     
 set objstream=nothing 
End Function 

'         
Function getHTTPPage(url) 
 'On Error Resume Next 
 dim http 
 set http=Server.createobject("Microsoft.XMLHTTP") 
 Http.open "GET",url,false 
 Http.send() 
 if Http.readystate<>4 then 
 exit function 
 end if 
 getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312") 
 set http=nothing 
 If Err.number<>0 then 
 getHTTPPage = "           " 
 Err.Clear 
 End If  
End function 

Function BytesToBstr(body,Cset) 
 dim objstream 
 set objstream = Server.CreateObject("adodb.stream") 
 objstream.Type = 1 
 objstream.Mode =3 
 objstream.Open 
 objstream.Write body 
 objstream.Position = 0 
 objstream.Type = 2 
 objstream.Charset = Cset 
 BytesToBstr = objstream.ReadText 
 objstream.Close 
 set objstream = nothing 
End Function 

'        
Function getpic(url) 
on error resume next 
dim http 
set http=server.createobject("MSXML2.XMLHTTP")'  xmlhttp            
Http.open "GET",url,false 
Http.send() 
if Http.readystate<>4 then 
exit function 
end if 
getpic=Http.responseBody 
set http=nothing 
if err.number<>0 then 
 getpic = "           " 
 err.Clear 
End if 
End Function 

'    (    ) 
Function OpenFile(fileurl)'       
 Dim Filename,fso,hndFile 
 Filename = fileurl 
 Filename = Server.MapPath(Filename) 
 Set objfso = CreateObject("Scripting.FileSystemObject") 
 If objfso.FileExists(Filename) Then 
 set hndFile = objfso.OpenTextFile(Filename) 
 OpenFile = hndFile.ReadAll 
 Else 
 OpenFile = "      " 
 End If 
 Set hndFile = Nothing 
 Set objfso = Nothing 
End Function 

'         
function getFileExtName(fileName) 
dim pos 
pos=instrrev(filename,".") 
if pos>0 then 
getFileExtName=mid(fileName,pos+1) 
else 
getFileExtName="" 
end if 
end function 

Dim fso,f,folder 
  Set fso=Server.CreateObject("scripting.filesystemobject") 
  '     
  Set folder=fso.getfolder(Server.Mappath("Old")) 
  folder.name="New" '    
  '     
  Set f=fso.getfile(Server.Mappath("Old.asp")) 
  f.name="New.asp" '    
'   
 
 
function copyfile(l1,l2)'     
  on error resume next  
  dim fs  
  set fs=createobject("Scripting.FileSystemObject")  
    fs.copyfile server.mappath(l1),server.mappath(l2)  
  set fs=nothing  
  if err.number<>0 then err.clear  
end function
copyfile("db1.mdb","db2.mdb")  
구체 적 인 건 검색 하 셔 도 됩 니 다.
FSO 조작 전집
아래 코드 도 vbs 에 적합 합 니 다.

<script language=vbs>
on error resume next
Set fso=CreateObject("Scripting.FileSystemObject") ' FSO     fso
 
    
getfso=fso.DriveExists("g:\") '             
getfso=fso.GetDrive("c:") '      FSO     
getfso=fso.GetDriveName("c:\       ") '          
Set getfso=fso.Drives '  FSO       ,   for each i in 
getfso        ,    [       ],   Count Item  
 
Set fso=Nothing '  fso   FSO       
</script>
드라이브 개체 조작

<script language=vbs>
on error resume next
Set fso=CreateObject("Scripting.FileSystemObject") ' FSO     fso    
getfso=fso.GetDrive("c:").FileSystem '              
getfso=fso.GetDrive("c:").DriveType '             ,     0-5
getfso=fso.GetDrive("c:").DriveLetter '          
getfso=fso.GetDrive("c:").IsReady '                 
getfso=fso.GetDrive("c:").SerialNumber '                 
getfso=fso.GetDrive("c:").ShareName '             
getfso=fso.GetDrive("c:").VolumeName '           ,           
getfso=fso.GetDrive("c:").Path '          , c:\   c:
getfso=fso.GetDrive("c:").RootFolder '            
getfso=fso.GetDrive("c:").AvailableSpace'              
getfso=fso.GetDrive("c:").FreeSpace '              
getfso=fso.GetDrive("c:").TotalSize '               
 
Set fso=Nothing '  fso   FSO       
</script>
시스템 폴 더 작업

<script language=vbs>
on error resume next
Set fso=CreateObject("Scripting.FileSystemObject") ' FSO     fso    
getfso=fso.GetFolder("c:\") '      FSO     
getfso=fso.FolderExists("e:\       ") '           
getfso=fso.GettempName '    WINDOW   temp         
getfso=fso.GetparentFolderName("e:\       ") '            
fso.CreateFolder "c:\windows\            "
fso.MoveFolder "c:\windows\          ","c:\windows\           "
fso.DeleteFolder "c:\windows\       ",false/true
fso.CopyFolder "c:\windows\       ","c:\windows\          ",false/true
Set getfso=fso.Folders '  FSO       ,   for each i in getfso        ,    [       ],   Count Item  ,  AddFolders  
Set getfso=fso.Files '  FSO          ,   for each i in getfso        ,    [      ],   Count Item  
Set fso=Nothing '  fso   FSO       
</script>
폴 더 개체 작업

<script language=vbs>
on error resume next
Set fso=CreateObject("Scripting.FileSystemObject") ' FSO     fso    
getfso=fso.GetFolder("c:\windows").Name '        ,    WINDOW
getfso=fso.GetFolder("c:\windows").ShortName '     [8.3]     
getfso=fso.GetFolder("c:\windows").Attributes '        ,   0,1,2,4,8,16,32,64,128
getfso=fso.GetFolder("c:\windows").Size '     (      )         
getfso=fso.GetFolder("c:\windows").Type '         
getfso=fso.GetFolder("c:\windows").Path '          
getfso=fso.GetFolder("c:\windows").ShortPath '     [8.3]     
getfso=fso.GetFolder("c:\windows").Drive '          
getfso=fso.GetFolder("c:\windows").Files.count '                
getfso=fso.GetFolder("c:\windows").SubFolders.count '                   
getfso=fso.GetFolder("c:\windows").ParentFolder '            
getfso=fso.GetFolder("c:\windows").IsRootFolder '            ,   true   false
getfso=fso.GetFolder("c:\windows").DateCreated '            
getfso=fso.GetFolder("c:\windows").DateLastAccessed '             
getfso=fso.GetFolder("c:\windows").DateLastModified '            
fso.GetFolder("c:\windows").CreateTextFile "         ",true/false,true/false
fso.GetFolder("c:\windows\       ").Delete true
fso.GetFolder("c:\windows\         ").Move "                    "
fso.GetFolder("c:\windows\   ").Copy "     ",true/false '           ,true=  ,false  
Set fso=Nothing '  fso   FSO       
</script>
시스템 파일 조작

<script language=vbs>
on error resume next
Set fso=CreateObject("Scripting.FileSystemObject") ' FSO     fso    
getfso=fso.GetFile("c:\windows\help.html") '        
getfso=fso.GetFileName("c:\windows\help.html") '         
getfso=fso.GetExtensionName("c:\windows\help.html") '         (  ),     
getfso=fso.FileExists("c:\windows\   .html") '        
fso.MoveFile "            ","              "
fso.DeleteFile "c:\windows\          ",false/true
fso.CopyFile "c:\windows\       .txt","c:\windows\       .jpg",false/true
fso.OpenTextFile "c:\windows\desktop\          .txt",1/2/8,true/false,0/-1/-2 'ForReading=1=    ,ForWriting=2=    ,ForAppending=8=    .true=                .TristateFalse=0=         ,TristateTrue=-1= Unicode      ,TristateUseDefaule=-2= ASCLL      (   )
fso.CreateTextFile "c:\windows\desktop\       .txt",false/true,false/true '  true         ,   true     Unicode    ,  =    
Set fso=Nothing '  fso   FSO       
</script>
파일 개체 조작

<script language=vbs>
on error resume next
Set fso=CreateObject("Scripting.FileSystemObject") ' FSO     fso    
getfso=fso.GetFile("c:\windows\   .txt").Name '             
getfso=fso.GetFile("c:\windows\   .txt").ShortName '       [8.3]      
getfso=fso.GetFile("c:\windows\   .txt").Attributes '         ,   0,1,2,4,8,16,32,64,128
getfso=fso.GetFile("c:\windows\   .txt").Size '         
getfso=fso.GetFile("c:\windows\   .txt").Type '         
getfso=fso.GetFile("c:\windows\   .txt").Path '           
getfso=fso.GetFile("c:\windows\   .txt").ShortPath '       [8.3]     
getfso=fso.GetFile("c:\windows\   .txt").Drive '             
getfso=fso.GetFile("c:\windows\   .txt").ParentFolder '            
getfso=fso.GetFile("c:\windows\   .txt").DateCreated '           
getfso=fso.GetFile("c:\windows\   .txt").DateLastAccessed '             
getfso=fso.GetFile("c:\windows\   .txt").DateLastModified '             
fso.GetFile("c:\windows\   .txt").Copy "          ",true/false
fso.GetFile("c:\windows\   .txt").Delete true
fso.GetFile("c:\windows\   .txt").Move "             
Set fso=Nothing '  fso   FSO       
</script>
 
파일 개체 읽 기와 쓰기 동작

<script language=vbs>
on error resume next
Set fso=CreateObject("Scripting.FileSystemObject") ' FSO     fso    
set link1=fso.GetFile("c:\windows\   .txt").OpenAsTextStream(1/2/8,0/-1/-2)
open1=link1.AtendOfline '              
open2=link1.AtendOfstream '               
open3=link1.Column '             
open4=link1.Line '             
open5=link1.Read(10) '            
open6=link1.ReadAll '          
open7=link1.ReadLine '             
open8=link1.Write "   " '                
open9=link1.WriteLine "  " '     +         
open10=link1.WriteBlankLines 10 '             
open11=link1.Skip 10 '              
open12=link1.SkipLine '          
link1.Close '      ,        
Set fso=Nothing '  fso   FSO       
</script>
이상 은 ASP FSO 파일 처리 함수 대전 의 상세 한 내용 입 니 다.더 많은 ASP FSO 파일 처리 에 관 한 자 료 는 저희 의 다른 관련 글 을 주목 해 주 십시오!

좋은 웹페이지 즐겨찾기