读取目录下的所有文件(包括子目录下的所有文件)
程序员文章站
2023-08-24 12:24:13
******************************
many times we might need some part of code which will...
******************************
many times we might need some part of code which will access all sub-folders of the server and also all
files within the sub-folder.
the following line of asp code will map to a specified folder and searches all the sub-folders
(not recursively, code can be extended to do) and reads all files(basically text files) one by one.
you can specify any folder name, in the remarks given in the code (within " ")
'create a file system object
set filesystem=server.createobject("scripting.filesystemobject")
dim dbconn
folderpath=server.mappath("main folder path" )
set sfolder=filesystem.getfolder(folderpath).subfolders
for each folderitem in sfolder
set files=folderitem.files
for each fileitem in files
fname=server.mappath( "main folder path" & folderitem.name & "\" & fileitem.name
set file=filesystem.opentextfile(fname,1,false)
while file.atendofstream <> true
record=split(file.readline,"~")
wend
file.close
filesystem.deletefile(fname)
next
next
******************************
many times we might need some part of code which will access all sub-folders of the server and also all
files within the sub-folder.
the following line of asp code will map to a specified folder and searches all the sub-folders
(not recursively, code can be extended to do) and reads all files(basically text files) one by one.
you can specify any folder name, in the remarks given in the code (within " ")
'create a file system object
set filesystem=server.createobject("scripting.filesystemobject")
dim dbconn
folderpath=server.mappath("main folder path" )
set sfolder=filesystem.getfolder(folderpath).subfolders
for each folderitem in sfolder
set files=folderitem.files
for each fileitem in files
fname=server.mappath( "main folder path" & folderitem.name & "\" & fileitem.name
set file=filesystem.opentextfile(fname,1,false)
while file.atendofstream <> true
record=split(file.readline,"~")
wend
file.close
filesystem.deletefile(fname)
next
next
******************************
下一篇: PS制作一颗超逼真的鸡蛋