首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CopyFile Vbscript

CopyFile Vbscript
EN

Stack Overflow用户
提问于 2013-02-14 00:13:53
回答 3查看 1.9K关注 0票数 0

我需要加入任何文件(2 2GB)而不读取其内容。我尝试过使用CopyFile方法,但它不起作用。

我的代码是:

代码语言:javascript
复制
Public Function UnificarCRIs(ByVal path, ByVal FICRIEC, ByVal sessio, ByVal CIBAA)
Dim objFile, objCurrentFolder, filesys, origenFitxers
Dim FileName, WshShell

On error resume next

Set filesys = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objCurrentFolder = filesys.getFolder(path)
origenFitxers = " "

For Each objFile In objCurrentFolder.Files
    FileName = objFile
    If (right(FileName, 4) = ".cri") Then
        origenFitxers = FileName
        'Wscript.Echo FileName
        If filesys.FileExists(path & FICRIEC & sessio) Then
            'Wscript.Echo "If"
            Wscript.Echo path & FICRIEC & sessio & "+" & FileName
            filesys.CopyFile path & FICRIEC & sessio & "+" & FileName, path & FICRIEC & sessio 
             'WshShell.Run ("copy " & path & FICRIEC & sessio & "+" & FileName & " " & path & FICRIEC & sessio & "_tmp")
            'filesys.DeleteFile path & FICRIEC & sessio
            'filesys.MoveFile path & FICRIEC & sessio & "_tmp", path & FICRIEC & sessio
        Else
            Wscript.Echo "Else"
            WshShell.Run ("copy " & FileName & " " & path & FICRIEC & sessio)
            'filesys.CopyFile FileName,path & FICRIEC & sessio
        End If  
    End If 
Next

End Function

有没有使用Vbscript连接两个文件的方法?

谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-02-14 00:28:38

取决于您有权访问哪些COM对象以及代码运行的位置。

1)如果您有权访问Shell,则使用DOS提示符的copy命令。此示例显示了Dir命令的执行,但这是相同的技术。

代码语言:javascript
复制
Dim oShell    
Set oShell = WScript.CreateObject ("WScript.Shell")

' Note the True value means wait to complete...
' And the 0 value means do not display any window...

oShell.run "cmd /K CD C:\ & Dir", 0, True  

Set oShell = Nothing

也许你也可以看看这里,http://ss64.com/vb/shellexecute.html。不知道这种方法是否会有帮助。

2)如果你没有外壳,那么如果你可以制作COM对象,那就用C++或Delphi或VB6等制作一个,然后使用该COM对象执行DOS命令进行合并。

3)否则,您将不得不从文件中读取数据。如果它是文本文件,那么这很容易,因为在Vbs中有简单的命令可以做到这一点。如果是二进制数据,则需要更多的工作来获取二进制数据,并使用"LenB“和"AscB”样式的函数来访问Unicode的原始字节。但是你真的不想这么做。ASP的任何上传处理脚本都应该向您展示使用字符串中的原始字节的技术。

票数 1
EN

Stack Overflow用户

发布于 2013-02-14 00:22:14

要连接两个文件,“某人”必须读取(和写入)这两个文件的内容。这个“人”可能是copy [/B] f1 + f2 f3。因此,使用您的循环构建正确的文件规范并WshShell.Run/.Exec suitabe命令。

票数 2
EN

Stack Overflow用户

发布于 2016-06-27 11:28:07

您可以将VBScript与Windows Copy命令结合使用来连接文件。您可以使用Copy here https://support.microsoft.com/en-us/kb/71161查看有关追加二进制文件的文档

以下是该技术的示例:

代码语言:javascript
复制
JoinFiles "c:\test\", "c:\test\mergedfile.cri"

Function JoinFiles (inPath, outPath)
    Dim objShell, objFSO

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = WScript.CreateObject("WScript.Shell")

    Dim strFilenames, objFile, intFilecount, intExitCode

    strFilenames = ""
    intFilecount = 0
    intExitCode = 0

    ' If the input folder exists, proceed to listing the files
    If objFSO.FolderExists (inPath) Then
        ' List the files in the folder and join the files which has cri extension
        For Each objFile In objFSO.GetFolder(inPath).Files
            If LCase (objFSO.GetExtensionName (objFile.Path)) = "cri" Then
                intFilecount = intFilecount+1
                strFilenames = strFilenames & """" & objFile.Path & """ + "
            End If
        Next

        ' If there're more than one file, proceed to join the file
        If (intFilecount > 1) Then
            ' join the files. Remove the last 3 characters from strFilenames (" + ").
            intExitCode = objShell.Run ("%COMSPEC% /C COPY /B " & Left (strFilenames, Len (strFilenames)-3) _
            & " """ & outPath & """ /Y", 0, True)
        Else
            ' Not enough file to join
        End If
    Else
        ' Can't find folder, exit.
    End If      
End Function
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14857904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档