在VB中如何实现dos的带参数copy /b filename1+filename2 filename3 命令行?

rongle 2000-08-22 11:07:00
...全文
324 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
fs_windy 2000-08-24
  • 打赏
  • 举报
回复
看看这个例子,或许是你要的答案:
http://210.77.145.209/dev/Visual%20Basic/source%20code/Executable%20File%20Related/Shell32.zip
lty 2000-08-24
  • 打赏
  • 举报
回复
必须注意命令行的总长度不能超出DOS的限制。实际很容易就超出127了。
rongle 2000-08-24
  • 打赏
  • 举报
回复
谢谢各位热心的大侠,我用shines大侠的方法用如下语句即可解决DOS窗口和异步执行问题:
I = Shell(winpath + "\Command.com /c copy /b /y sysdat2.mdb + sysdat1.mdb + sysdat3.mdb " + winsyspath + "\minitool.exe", vbHide)
p = OpenProcess(SYNCHRONIZE, False, I)
r = WaitForSingleObject(p, INFINITE)
r = CloseHandle(p)
...
playyuer 2000-08-23
  • 打赏
  • 举报
回复
上面的方法都是异步的,我建议自己编一个,参阅:
Sub MyFileCopy(sFileName0 As String, sFilename As String, Optional N As Long = 0)
'当 N=0时 ,即 为 Copy
Const KB = 1024
Dim nKB As Long
nKB = 64
Dim FileBuffer() As Byte
Dim FileNumberS As Long
Dim FileNumberT As Long
Dim lFileLen As Long
lFileLen = FileLen(sFileName0) - N
FileNumberS = FreeFile
Open sFileName0 For Binary Access Read As #FileNumberS
FileNumberT = FreeFile
Open sFilename For Binary Access Write As #FileNumberT
ReDim FileBuffer(1 To (nKB * KB)) As Byte '设 置 缓 冲 区 大 小 为 64K
'若 用 Do Until LOF(FileNumber)
' ...
' Loop 语 句 ,
'不 方 便 ,复 杂 !
Do While lFileLen >= (nKB * KB)
Get #FileNumberS, , FileBuffer
Put #FileNumberT, , FileBuffer
lFileLen = lFileLen - (nKB * KB)
Loop
If lFileLen > 0 Then
ReDim FileBuffer(1 To lFileLen) As Byte
Get #FileNumberS, , FileBuffer
Put #FileNumberT, , FileBuffer
End If
Close #FileNumberS
Close #FileNumberT
MsgBox "End!"
End Sub
tg123 2000-08-23
  • 打赏
  • 举报
回复
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal_
lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) _
As Long

ShellExecute 0, "Open", "c:\windows\Command.com /k copy /b filename1+filename2 filename3" , "", "C:\", 1
wuf 2000-08-23
  • 打赏
  • 举报
回复
这个问题注意三个方面:
1.命令就是纯dos的命令
2.不出现DOS窗口
3.不能异步执行,这句还没执行完,就执行下面语句了
在http://wuf.yeah.net/有这三个问题的详细解决方案
有进一步的要求, 可向我索要另外的源码
例如:
If Len(mlm) <= 3 Or Right(mlm, 1) = "\" Then
MsgBox "目的目录不允许为根目录且不用加 \"
Text2.SetFocus
Exit Sub
End If

If Len(Trim(Dir(mlm, 16))) > 0 Then
Dim Response
SendKeys "{TAB}"
Response = MsgBox("目录 [" & mlm & "] 已存在,你确信删除吗?", vbYesNo, "【提醒】")
If Response = 6 Then
Shell "Command.com /C deltree.exe /y " & mlm, vbMinimizedNoFocus
Else
MsgBox "由于该目录已存在,程序停止传送文件!"
Exit Sub
End If
End If

Do While Len(Trim(Dir(mlm, 16))) > 0
Loop

MkDir (mlm)
shines77 2000-08-23
  • 打赏
  • 举报
回复
应该是 Shell "command.com /c copy /b /y c:\我的文档\action.txt + c:\我的文档\biye.txt + c:\我的文档\Black.txt c:\我的文档\copybb.txt" ,vbNormalFocus

绝对OK!,你必须给每个文件加上路径才行,另外是 command.com /c 才能自动关闭DOS窗口 /k 只能停在DOS窗口,相信我没错。
rongle 2000-08-23
  • 打赏
  • 举报
回复
但是运行到shellexecute...时出现文件不存在错误,我的该行程序如下:ShellExecute 0, "Open", "c:\windows\Command.com /k copy /b sysdat1.001 + sysdat2.002 + sysdat3.003 c:\tool\minitool.exe", "", "C:\", 1
rongle 2000-08-22
  • 打赏
  • 举报
回复
能不能不让出现dos窗口,且执行完后继续下面的程序?
fs_windy 2000-08-22
  • 打赏
  • 举报
回复
试试下面
Shell "c:\windows\Command.com /k copy /b filename1+filename2 filename3", vbNormalFocus

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧