在每个驱动器上创建一个文件夹 [英] creating a folder on each drive
问题描述
我正在尝试找到一种可以在所有现有驱动器上创建文件夹的VB方式 - 文件夹名称在每个驱动器上都是相同的。即
c:\ backup,d:\ backup等等。但只有
它们不存在时才能创建文件夹,如果驱动器碰巧是一个文件夹
无法创建(即cdrom驱动器)它只会被跳过
没有代码产生任何错误。
你对这方面的帮助将非常感激。 jenny
Hi, I am trying to find a VB way that would create a folder on all
existing drives - the folder name would be the same on each drive. ie
c:\backup, d:\backup, etc. But the folders would only be created if
they don''t already exist, and if the drive happens to be one a folder
cannot be created on (ie a cdrom drive) it would just be skipped
without the code generating any errors.
your help on this would be most appreciated. jenny
推荐答案
je**@onlink.net ( jenny)在留言新闻中写道:< 3d ************************** @ posting.google。 com> ...
je**@onlink.net (jenny) wrote in message news:<3d**************************@posting.google. com>...
您好,我正在尝试找到一种可以在所有现有驱动器上创建文件夹的VB方式 - 文件夹名称在每个驱动器上都是相同的。即
c:\ backup,d:\ backup等。但是只有当文件夹不存在时才会创建文件夹,如果驱动器恰好是一个文件夹
无法创建(即cdrom驱动器)它只是被跳过
没有代码产生任何错误。
你的帮助将非常感激。 jenny
Hi, I am trying to find a VB way that would create a folder on all
existing drives - the folder name would be the same on each drive. ie
c:\backup, d:\backup, etc. But the folders would only be created if
they don''t already exist, and if the drive happens to be one a folder
cannot be created on (ie a cdrom drive) it would just be skipped
without the code generating any errors.
your help on this would be most appreciated. jenny
你可以使用FSO,唯一的缺点是(除了必须
参考它)
它可以在用户机器上关闭。
我会避免使用以下FSO。
私有声明函数GetLogicalDrives Lib" kernel32" ()As Long
用它来创建一个按位循环来给你驱动器
私有声明函数GetDriveType Lib" kernel32" Alias
" GetDriveTypeA" (ByVal nDrive As String)As Long
用于清除不需要的驱动器CD等等
您还可以在循环中使用instr mid
如果您想要创建一次多个文件夹
例如创建/全部/这些/文件夹/ in / one / go
You can use the FSO, the only drawback is (apart from having to
reference it)
it can be optionaly switched off on a users machine.
I would avoid using the FSO with the following.
Private Declare Function GetLogicalDrives Lib "kernel32" () As Long
Use it to Create a Bitwise loop to give you the drives
Private Declare Function GetDriveType Lib "kernel32" Alias
"GetDriveTypeA" (ByVal nDrive As String) As Long
Use to rid unwanted drives CD''s etc
VB''s DIR to see if folders exist & MKDIR to create them.
You can also use instr mid etc in the loop
if you want to get fancy to create one time multiple folders
e.g. Create/All/These/Folders/in/one/go
> >我试图找到一种VB方式,可以在所有
> > Hi, I am trying to find a VB way that would create a folder on all
现有驱动器上创建一个文件夹 - 每个驱动器上的文件夹名称都是相同的。即
c:\ backup,d:\ backup等。但是只有当文件夹不存在时才会创建文件夹,如果驱动器恰好是一个文件夹
无法创建(即cdrom驱动器)它只是被跳过
没有代码产生任何错误。
你的帮助将非常感激。 jenny
existing drives - the folder name would be the same on each drive. ie
c:\backup, d:\backup, etc. But the folders would only be created if
they don''t already exist, and if the drive happens to be one a folder
cannot be created on (ie a cdrom drive) it would just be skipped
without the code generating any errors.
your help on this would be most appreciated. jenny
你可以使用FSO,唯一的缺点是(除了必须参考它)
它可以在用户机器上选择关闭。
我会避免使用FSO以下内容。
私有声明函数GetLogicalDrives Lib" kernel32" ()As Long
使用它创建一个按位循环来为你提供驱动器
私有声明函数GetDriveType Lib" kernel32"别名
GetDriveTypeA (ByVal nDrive As String)As Long
用于清除不需要的驱动器CD等等
VB的DIR以查看文件夹是否存在& MKDIR来创建它们。
You can use the FSO, the only drawback is (apart from having to
reference it)
it can be optionaly switched off on a users machine.
I would avoid using the FSO with the following.
Private Declare Function GetLogicalDrives Lib "kernel32" () As Long
Use it to Create a Bitwise loop to give you the drives
Private Declare Function GetDriveType Lib "kernel32" Alias
"GetDriveTypeA" (ByVal nDrive As String) As Long
Use to rid unwanted drives CD''s etc
VB''s DIR to see if folders exist & MKDIR to create them.
如何使代码更简单?
Dim X As Integer
On Error Resume Next
For X = Asc(" c")To Asc(" z")
MkDir Chr
What about making the code even simpler?
Dim X As Integer
On Error Resume Next
For X = Asc("c") To Asc("z")
MkDir Chr
>
(X)& ":\ backup"
下一页
Rick - MVP
(X) & ":\backup"
Next
Rick - MVP
这篇关于在每个驱动器上创建一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!