zoukankan      html  css  js  c++  java
  • asp创建文件与文件夹

    一、创建文件夹

    1.创建一层的文件夹

    Dim fs,strFolder
    '创建一目录下,只有一层的文件夹
    strFolder="Logs"
    Err.Clear
    On Error Resume Next
    '创建文件对象
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    strFolder=Server.MapPath("\"&strFolder)
    '判断文件夹是否存在,不存在就创建
    If not fs.FolderExists(strFolder) Then
    fs.CreateFolder strFolder
    End If

    If Err.Number<> 0 Then
    Response.Write "文文件夹创建失败,失败原因:"&Err.Description
    Else
    Response.Write "文件夹创建成功!"
    End If

    2.创建多层的文件夹

    Dim fs,strFolder
    Dim arrPath,i,ulngArrPath,tempFolder
    '创建一目录下,只有一层的文件夹
    strFolder="Logs\Web\Test"
    Err.Clear
    On Error Resume Next
    '创建文件对象
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    arrPath=Split(strFolder,"\")
    ulngArrPath=ubound(arrPath)
    for i=0 to ulngArrPath
    tempFolder=tempFolder&"\"&arrPath(i)
    strFolder=Server.MapPath(tempFolder)
    '判断文件夹是否存在,不存在就创建
    If not fs.FolderExists(strFolder) Then
    fs.CreateFolder strFolder
    End If
    next

    If Err.Number<> 0 Then
    Response.Write "文件夹创建失败,失败原因:"&Err.Description
    Else
    Response.Write "文件夹创建成功!"
    End If

    二、创建Text文件

    Dim fs,strFile
    '创建一目录下,只有一层的文件夹
    strFile="Logs.txt"
    Err.Clear
    On Error Resume Next
    '创建文件对象
    set fs=Server.CreateObject("Scripting.FileSystemObject")

    strFile=Server.MapPath("\"&strFile)
    '判断文件夹是否存在,不存在就创建
    If not fs.FileExists(strFile) Then
    fs.CreateTextFile strFile
    End If

    If Err.Number<> 0 Then
    Response.Write "文件创建失败,失败原因:"&Err.Description
    Else
    Response.Write "文件创建成功!"
    End If

  • 相关阅读:
    HTML <button> 标签
    git帮助命令
    PHP从数组中删除元素的方法
    thinkphp里面的or查询
    登录操作中的记住密码操作的算法逻辑
    重复密码需一致的表单实例
    判断 checkbox 是否选中以及 设置checkbox选中
    update和saveOrUpdate具体解释
    gopkg:一种方便的go pakcage管理方式
    一次正确选择,改变一生命运!
  • 原文地址:https://www.cnblogs.com/ljx2012/p/2689065.html
Copyright © 2011-2022 走看看