找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 162|回复: 0

根据文件路径创建文件夹

[复制链接]

27

主题

11

回帖

151

积分

管理员

积分
151
发表于 2024-4-6 00:01:06 | 显示全部楼层 |阅读模式
给定指定路径,则创建这个路径中的所有文件夹。
例如,文件路径:"E:\movies\us\thred.mp4"
则此函数会创建文件夹:"movies","us"
  1. Public Sub CreateFolder(ByVal FilePath As String)
  2.     Dim arr() As String
  3.     Dim i As Long
  4.     Dim curPath As String
  5.    
  6.     FilePath = Replace(FilePath, "\", "")
  7.    
  8.     If Dir(FilePath, vbDirectory) = "" Then
  9.         FilePath = Mid(FilePath, 1, InStrRev(FilePath, ""))
  10.     End If
  11.    
  12.     arr = Split(FilePath, "")
  13.    
  14.     For i = 0 To UBound(arr)
  15.         If curPath = "" Then
  16.             curPath = curPath & arr(i)
  17.         Else
  18.             curPath = curPath & "" & arr(i)
  19.         End If
  20.         
  21.         If Dir(curPath, vbDirectory) = "" Then
  22.             MkDir curPath
  23.         End If
  24.     Next i
  25. End Sub
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|编程客 ( 鄂ICP备19023849号-1 )

GMT+8, 2025-6-14 03:07 , Processed in 0.029750 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表