zoukankan      html  css  js  c++  java
  • ASP 按修改时间读取文件夹中文件并且排序

    Private Type typFlieDate
    Name As String
    CreatedDate As Date
    AccessedDate As Date 
    ModifiedDate As Date
    End Type

    Private myFiles() As typFlieDate '包含文件的数组
    Private Sub Command1_Click()
    Dim n As Integer
    n = GetFolderFiles( "d:\" , 1)
    End Sub

    Private Function GetFolderFiles(Path As String, OrderBy As Integer) As Integer
    'path 文件夹路径
    'orderby 排序依据 1:按创建时间 2:按访问时间 3:按修改时间 4:按名称
    '返回文件夹中文件的个数
    '如果要计算子文件夹可以通过 fldr.SubFolders 访问,方法类似

    Dim tmpFile As typFlieDate
    Dim n As Integer, i As Integer, j As Integer
    Dim fso As New FileSystemObject
    Dim fldr As Folder
    Dim fls As Files
    Dim fl As File

    '读去文件
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fldr = fso.GetFolder(Path)
    Set fls = fldr.Files
    n = fls.Count
    If n > 0 Then
    ReDim myFiles(n - 1)
    i = 0
    For Each fl In fls
    myFiles(i).Name = fl.Name
    myFiles(i).AccessedDate = fl.DateLastAccessed
    myFiles(i).CreatedDate = fl.DateCreated
    myFiles(i).ModifiedDate = fl.DateLastModified
    i = i + 1
    Next
    '排序 --- 升序
    For i = 0 To n - 1
    For j = i + 1 To n - 1
    Select Case OrderBy
    Case 1 '创建时间
    If myFiles(i).CreatedDate > myFiles(j).CreatedDate Then
    tmpFile = myFiles(i)
    myFiles(i) = myFiles(j)
    myFiles(j) = tmpFile

    ' tmpFile.Name = myFiles(i).Name
    ' tmpFile.AccessedDate = myFiles(i).AccessedDate
    ' tmpFile.CreatedDate = myFiles(i).CreatedDate
    ' tmpFile.ModifiedDate = myFiles(i).ModifiedDate
    '
    ' myFiles(i).AccessedDate = myFiles(j).AccessedDate
    ' myFiles(i).CreatedDate = myFiles(j).CreatedDate
    ' myFiles(i).ModifiedDate = myFiles(j).ModifiedDate
    ' myFiles(i).Name = myFiles(j).Name
    '
    ' myFiles(j).AccessedDate = tmpFile.AccessedDate
    ' myFiles(j).CreatedDate = tmpFile.CreatedDate
    ' myFiles(j).ModifiedDate = tmpFile.ModifiedDate
    ' myFiles(j).Name = tmpFile.Name
    End If

    Case 2 '访问时间
    If myFiles(i).AccessedDate > myFiles(j).AccessedDate Then
    tmpFile = myFiles(i)
    myFiles(i) = myFiles(j)
    myFiles(j) = tmpFile
    End If
    Case 3 '修改时间
    If myFiles(i).ModifiedDate > myFiles(j).ModifiedDate Then
    tmpFile = myFiles(i)
    myFiles(i) = myFiles(j)
    myFiles(j) = tmpFile
    End If
    Case 4 '名称
    If UCase(myFiles(i).Name) > UCase(myFiles(j).Name) Then
    tmpFile = myFiles(i)
    myFiles(i) = myFiles(j)
    myFiles(j) = tmpFile
    End If
    End Select
    Next j
    Next i
    End If
    GetFolderFiles = n
    End Function

  • 相关阅读:
    根据group by、count case when 分组分类统计
    Cron表达式
    SQL分页查询 — 不同页面的查询结果有重复数据
    Dockerfile文件语法
    redis获取系统当前时间
    mybatis oracle批量插入数据
    Mysql函数->TRIM(去掉首尾空格、任意字符)
    Oracle函数->TRIM(去掉首尾空格、首尾字符)
    使用redis-list类型 限制用户1分钟内访问次数为100次
    一文了解mysql基础架构
  • 原文地址:https://www.cnblogs.com/cosiray/p/1551872.html
Copyright © 2011-2022 走看看