备份cmd=xcopy如何设置最大千字节pro vid以进行下行?不应将大于 100000 KB 的视频复制到 USB



我尝试只备份私人视频而不备份大电影。

大于100000 KB的视频不应复制到USB。我尝试跳过所有大于100MB的视频有什么想法吗?

[autorun] 
@echo off 
:: variables 
/min 
SET odrive=%odrive:~0,2% 
set backupcmd=xcopy /s /c /d /e /h /i /r /y 
echo off
%backupcmd% "%USERPROFILE%videos" "%drive%allvids"
@echo off 
cls 

您可以使用XCopy命令的/EXCLUDE标志来完成此操作=这将指向具有排除的文件类型或文件夹或文件名的文件

您可以通过在控制台上键入以下内容来查看XCopy的帮助:XCopy/

在我们的示例中,我们排除了由vbscript创建的大于100 Mo的所有文件。

Option Explicit
Const size_limit = 100000000 'bytes
Dim FSO,ws,MyFolder,MyExcludeFile,LogTmpFile,LogFile,MyCmd,sSrc,sDest
Set FSO = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("wscript.Shell")
sSrc = "e:Films"
sDest = "e:TestCopyFilms"
Set MyFolder = FSO.GetFolder(sSrc)
MyExcludeFile = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "txt"
LogTmpFile = "MyTmpXCopyLog.txt"
LogFile = "MyXCopyLog.txt"
If fso.FileExists(MyExcludeFile) Then
    fso.DeleteFile(MyExcludeFile)
End If  
Call ListSubFolders(MyFolder)
MyCmd = "XCopy" & " " & sSrc & " " & sDest & " /s /c /d /e /h /i /r /y /EXCLUDE:"& MyExcludeFile &" > " & LogTmpFile &_
" & cmd /U /C Type " & LogTmpFile & " > " & LogFile & " & Del " & LogTmpFile & ""
Call Executer(MyCmd,0)
ws.run LogFile
'*********************************************************************************************
Sub ListSubFolders(Folder)
    Dim Subfolder,File
    For Each Subfolder in Folder.SubFolders
        For Each File in Subfolder.Files
            If (File.Size > size_limit) Then
                Call WriteLog("" & File.Name & "")
            End If
        Next
        ListSubFolders Subfolder
    Next
End Sub 
'**********************************************************************************************
Sub WriteLog(strText)
    Dim fs,ts,MyExcludeFile
    Const ForAppending = 8
    MyExcludeFile = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "txt"
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile(MyExcludeFile,ForAppending,True)
    ts.WriteLine strText
    ts.Close
End Sub
'***********************************************************************************************
Function Executer(StrCmd,Console)
    Dim ws,MyCmd,Resultat
    Set ws = CreateObject("wscript.Shell")
'La valeur 0 pour cacher la console MS-DOS
    If Console = 0 Then
        MyCmd = "CMD /C " & StrCmd & " "
        Resultat = ws.run(MyCmd,Console,True)
        If Resultat = 0 Then
'MsgBox "Success"
        Else
            MsgBox "Une erreur inconnue est survenue !",16,"Une erreur inconnue est survenue !"
        End If
    End If
'La valeur 1 pour montrer la console MS-DOS
    If Console = 1 Then
        MyCmd = "CMD /K " & StrCmd & " "
        Resultat = ws.run(MyCmd,Console,False)
        If Resultat = 0 Then
'MsgBox "Success"
        Else
            MsgBox "Une erreur inconnue est survenue !",16,"Une erreur inconnue est survenue !"
        End If
    End If
    Executer = Resultat
End Function
'****************************************************************************************************

最新更新