导航:首页 > 文件处理 > vb复制文件夹命令

vb复制文件夹命令

发布时间:2022-10-05 17:53:10

Ⅰ vb中复制文件

用API函数 SHFileOperation的方法。

Ⅱ VB复制文件夹中文件,以指定路径的文件夹中文件复制到另一个文件夹!

VB6.0使用CopyFile 方法来实现把一个或多个文件从一个地方复制到另一个地方。

  1. CopyFile 方法。

    描述,把一个或多个文件从一个地方复制到另一个地方。

  2. 语法:

  3. 说明

    通配符只能用在 source 参数的最后一个路径部件。例如你可以在下面请况使用通配符:

    FileSystemObject.CopyFile "c:mydocumentsletters*.doc", "c: empfolder"

    但下面情况不能使用:

    FileSystemObject.CopyFile "c:mydocuments*R1???97.xls", "c: empfolder"

    如果 source 包含通配符或 destination以路径分隔符()为结尾,则认为 destination是一个已存在文件夹,在其中复制相匹配的文件。否则认为 destination
    是一个要创建文件的名字。不论是那种情况,当复制一个文件时,可能发生三种事件。

    1. 如果 destination 不存在,source 得到复制。这是通常的情况。

    2.如果 destination 是一个已存在的文件,则当 overwrite 值为 False 时发生一个错误,否则,source的复制文件将试图覆盖已存在文件。

    3.如果 destination 是一个目录,发生一个错误

    如果使用通配符的 source 不能和任何文件匹配,同样产生一个错误。CopyFile
    方法停止在它遇到的第一个错误上。不要试图回卷或撤消错误发生前所做的任何改变。

Ⅲ 如何用VB复制、移动、删除文件、文件夹

1.利用FileCopy语句复制文件
Private Sub Command1_Click() '复制文件
If Text1.Text = "" Or Text2.Text = "" Then
MsgBox "输入不能为空值"
Else
FileCopy Text1.Text, Text2.Text '复制文件
MsgBox "文件复制成功!", vbInformation, "明日图书"
End If
End Sub
Private Sub Command3_Click() '选择文件存放的路径
CommonDialog1.ShowSave
Text2.Text = CommonDialog1.FileName
End Sub
Private Sub Command4_Click() '选择要复制文件的路径
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName
End Sub
2.利用MoveFile函数移动文件
Private Declare Function MoveFile Lib "kernel32" Alias "MoveFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String) As Long
Private Sub Command1_Click()
If txt_ywj.Text = "" Or txt_mbwj.Text = "" Then
MsgBox "输入不能为空值", vbInformation, "明日图书"
Else
MoveFile Text1.Text, Text2.Text '实现文件移动的过程
MsgBox "文件移动成功!", vbInformation, "明日图书"
End If
End Sub
Private Sub Command3_Click() '选择文件移动后的路径
CommonDialog1.ShowSave
Text1.Text = CommonDialog1.FileName
End Sub
Private Sub Command4_Click() '选择要移动文件所在的路径
CommonDialog1.ShowOpen
Text2.Text = CommonDialog1.FileName
End Sub
3.删除文件夹
要想删除文件夹,可以利用文件对象的DeleteFolder方法完成文件的删除操作。该方法可以将文件夹和文件夹中的内容全部删除,并不对文件夹中是否有内容进行判断。由于DeleteFolder方法是FSO对象的方法,所以在使用该方法前需要对FSO对象进行引用。通过选择Visual Basic菜单中的“工程”→“引用”命令,在弹出的“引用”对话框中选中“Microsoft Scripting Runtime”复选框,单击“确定”按钮,即可引用该对象。
运行程序,单击“<<”按钮,选择要删除的文件夹,然后单击“删除”按钮,此时会弹出提示信息对话框,单击“确定”按钮,即可将该文件夹删除,如图13.7所示。
关键代码如下:
Dim STStr As String
Dim SSTr As String
Dim fso As New FileSystemObject
Private Sub Command1_Click()
Dim FPaths As String
FPaths = FPath$(Me.hWnd, "浏览系统文件夹")
Text1.Text = FPaths
End Sub
Private Sub Command2_Click()
Dim c As Integer
Call RiStr
c = MsgBox("确认将该文件夹删除吗?", 17, "提示信息")
If c = vbOK Then
fso.DeleteFolder Text1.Text '删除文件夹
MsgBox "文件夹已经被成功删除!", 64, "提示信息"
End If
End Sub
Private Sub RiStr()
Dim YWJ, MWJ, L As String, S As String * 1, ASCIIN, i As Integer
MWJ = ""
YWJ = RTrim$(Text1.Text)
L = Len(YWJ)
For i = 1 To L
S = Right$(YWJ, i)
If Left$(S, 1) = "\" Then
Dim RStr As String
RStr = Right$(YWJ, i - 1)
SSTr = Mid(Text1.Text, 1, Len(Text1.Text) - Len(RStr))
Exit Sub
End If
Next i
End Sub

Ⅳ vb中如何将一个文件的所有东西复制到另一个文件夹

调用外部的dos
的命令,可以实现的要求...
shell
"cmd
/c

c:\1.doc
d:\001\"
用vb的文件复制,需要指定目标文件的姓名.
不过这样不符合你的要求.
Dim
result,
Sourcefile,
Destinationfile
As
String
result
=
MsgBox(
"确定要复制吗?
",
vbYesNo,
"询问
")
If
result
=
vbYes
Then
Sourcefile
=
"c:\1.doc"
Destinationfile
=
"d:\001\1.doc"
FileCopy
Sourcefile,
Destinationfile
End
If

Ⅳ 在VB中如何复制文件

1.VB自己的命令 file text1.text,text2.text 2.VBS的命令 Set fso = CreateObject("Scripting.FileSystemObject") fso. text1.text,text2.text 全部删除复制 移动的如下: dim a,b,c On Error Resume Next c=inputbox("请输入操作代码:1.删除;2.复制,3.移动","6921833","D:") a=inputbox("请输入源文件的目录","6921833","D:") if c<>1 then b=inputbox("请输目标文件夹","6921833","D:") else b=0 end if Tree(a,b,c) Set WshSHell = WScript.CreateObject("WScript.Shell") msgbox"OK" Function Tree(sPath,spath2,whatdo) On Error Resume Next Dim WshSHell,oFso Set oFso = CreateObject("Scripting.FileSystemObject") Set oFolder = oFso.GetFolder(sPath) Set oSubFolders = oFolder.Subfolders Set oFiles = oFolder.Files For Each oFile In oFiles '文件 if whatdo=1 then oFile.delete elseif whatdo=2 then oFile.Copy (spath2) elseif whatdo=3 oFile.Movw (spath2) end if Next For Each oSubFolder In oSubFolders TreeIt(oSubFolder.Path)'递归 Next Set objFolder=oFso.Getfolder(a) Set subFolders=objFolder.subFolders For Each subFolder In subFolders On Error Resume Next if whatdo=1 then subfolder.Delete(True) If Err Then err.Clear Else End If Next Set oFolder = Nothing Set oSubFolders = Nothing Set oFso = Nothing End Function

Ⅵ VB做复制文件到指定的文件夹

资源释放吧 然后添加那个文件 释放命令 Private Sub Command1_Click()on error resume next
dim app1() as byte
if dir(app.path & "/文件名") = "" then
app1 = loadresdata(101,"custom")
open app.path & "/文件名" for binary as #2
put #2 ,, app1
close #2
end if End Sub

Ⅶ 如何用VB复制、移动、删除文件、文件夹

VB
文件操作命令:
Kiil
"路径"
删除文件
Mkdir
"路径"
建立文件夹
FileCopy
"路径","目的地"
复制文件
Name
"路径1"
As
"路径2"
重命名

阅读全文

与vb复制文件夹命令相关的资料

热点内容
java权限系统源码 浏览:163
androidmk编译aidl 浏览:880
单片机取8位 浏览:994
如何在云服务器上安装2s 浏览:7
怎么把王者安卓号转移到苹果 浏览:779
思科密码加密后怎么登录 浏览:591
安卓手机生态垃圾怎么办 浏览:113
fy187 浏览:597
python中文文字识别 浏览:882
日本蕾丝边电影 浏览:796
斯坦福编译原理讲义 浏览:147
国外大尺度漏器官电影 浏览:433
玩具解压神器怎么做 浏览:299
安卓手机如何共存歌曲 浏览:426
简单的游戏代码源码 浏览:346
金蝶服务器怎么改 浏览:595
h y p 6.vip 浏览:709
韩国战争电影十大巅峰之作 浏览:425
大尺度百合剧 浏览:112
为什么要叫毒app 浏览:492