簡體   English   中英

復制文件Vbscript

[英]CopyFile Vbscript

我需要加入任何文件(2GB)而不讀取其內容。 我試圖使用CopyFile方法,但是它不起作用。

我的代碼是:

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連接兩個文件嗎?

謝謝

要連接兩個文件,“某人”必須讀取(和寫入)兩個文件的內容。 這個“某人”可以是copy [/B] f1 + f2 f3 因此,請使用循環構建正確的文件規范,並使用suitabe命令WshShell.Run/.Exec

取決於您有權訪問哪些COM對象以及代碼在何處運行。

1)如果您有權訪問命令行管理程序,請使用DOS提示符下的copy命令。 此示例顯示了Dir命令的執行方式,但這是相同的技術。

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對象。然后使用該COM對象執行DOS命令進行合並。

3)否則,您將不得不從文件中讀取數據。 如果它是文本文件,那么這很容易,因為在Vb中有簡單的命令可以執行此操作。 如果它是二進制數據,則需要更多的工作來獲取二進制數據並使用“ LenB”和“ AscB”樣式函數來訪問Unicode的原始字節。 但是您真的不想這樣做。 任何適用於ASP的上傳處理腳本都應向您展示使用字符串中的原始字節的技術。

您可以將VBScript與Windows Copy命令結合使用以加入文件。 您可以使用此處的復制https://support.microsoft.com/zh-cn/kb/71161看到有關附加二進制文件的文檔

這是該技術的示例:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM