Vbscript 创建包含多个目录和文件的备份文件夹

Vbscript 创建包含多个目录和文件的备份文件夹,vbscript,Vbscript,我在这方面是新手,我正在尝试获得一个VBScript(因为应用程序只适用于此),它可以备份多个目录和文件 例如: Check if Folder1 exist... (It may be on c:\ or another drive) If don´t exist the finish If exist than should create a Bck Folder THan Backup the folders that are inside folder1 (Folder2, Folder

我在这方面是新手,我正在尝试获得一个VBScript(因为应用程序只适用于此),它可以备份多个目录和文件

例如:

Check if Folder1 exist... (It may be on c:\ or another drive)
If don´t exist the finish
If exist than should create a Bck Folder
THan Backup the folders that are inside folder1 (Folder2, Folder3)
Also backup all the files that are *.mds, *.vbs inside Folder4
The script have to maintain the struture...
And after that delete all folder1
这就是我到目前为止所做的:

IF NOT EXIST "%INSTALLDIR%\Folder1\" GOTO ENDPROG 
mkdir "%INSTALLDIR%\BCK\" 
mkdir "%INSTALLDIR%\BCK\DADOS\" 
mkdir "%INSTALLDIR%\BCK\IMAGEM\" 
mkdir "%INSTALLDIR%\BCK\CONFIG\" 
mkdir "%INSTALLDIR%\BCK\OFFBck" 
copy "%INSTALLDIR%\Folder1\Dados*.MDB" "%INSTALLDIR%\BCK\dados\" 
copy "%INSTALLDIR%\Folder1\Dados*.MDD" "%INSTALLDIR%\BCK\dados\" 
copy "%INSTALLDIR%\Folder1\Dados*.VEI" "%INSTALLDIR%\BCK\dados\" 
copy "%INSTALLDIR%\Folder1\Imagem*.*" "%INSTALLDIR%\BCK\Imagem\" 
copy "%INSTALLDIR%\Folder1*.cfg" "%INSTALLDIR%\BCK\Config\" 
copy "%INSTALLDIR%\Folder1\OFFbck*.ZIP" "%INSTALLDIR%\BCK\OFFbck\" 
copy "%INSTALLDIR%\Folder1\Folder1\OFFbck*.ZIP" "%INSTALLDIR%\BCK\OFFbck\" 
rmdir "%INSTALLDIR%\Folder1" /s /q 
:ENDPROG 
谁能帮我一下吗

我已经这样做了…但是如果备份的文件夹已经存在,我会给出一个错误…但是我无法开始复制

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists("C:\Folder1") Then
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Const OverwriteExisting = TRUE
    Set objFolder = objFSO.CreateFolder("C:\BCK")
    Set objFolder = objFSO.CreateFolder("C:\BCK\Imagem")
    Set objFolder = objFSO.CreateFolder("C:\BCK\dados")
    Set objFolder = objFSO.CreateFolder("C:\BCK\config")
    Set objFolder = objFSO.CreateFolder("C:\BCK\off")
Else
End If
提前谢谢

我刚刚创造了这个

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists("C:\audatex") Then
    Const OverwriteExisting = True
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.CreateFolder("C:\BCK")
    Set objFolder = objFSO.CreateFolder("C:\BCK\Imagem")
    Set objFolder = objFSO.CreateFolder("C:\BCK\dados")
    Set objFolder = objFSO.CreateFolder("C:\BCK\WTB")
    Set objFolder = objFSO.CreateFolder("C:\BCK\CFG")
    Set objFolder = objFSO.CreateFolder("C:\BCK\config")
    Set objFolder = objFSO.CreateFolder("C:\BCK\offdaten")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.CopyFile "C:\Audatex\offdaten\*.zip" , "c:\BCK\Offdaten\" , OverwriteExisting
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.CopyFile "C:\Audatex\Dados\*.vei" , "c:\BCK\dados\" , OverwriteExisting
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.CopyFile "C:\Audatex\Dados\*.mdd" , "c:\BCK\dados\" , OverwriteExisting
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.CopyFile "C:\Audatex\*.cfg" , "c:\BCK\CFG\" , OverwriteExisting
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.CopyFile "C:\Audatex\Dados\*.mdb" , "c:\BCK\dados\" , OverwriteExisting
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.CopyFolder "C:\Audatex\Imagem" , "c:\BCK\Imagem" , OverwriteExisting
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.CopyFile "C:\Audatex\WTB\*.wtb" , "c:\BCK\WTB\" , OverwriteExisting
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.CopyFile "C:\Audatex\WTB\*.dtb" , "c:\BCK\WTB\" , OverwriteExisting
End IF  
但我知道我有以下问题:如果文件夹上没有任何内容,我会出错,无法覆盖文件夹


谢谢

您可以复制以特定字符串开头的具有特定扩展名的文件,如下所示:

For Each f In objFSO.GetFolder("C:\Folder1").Files
  ext = LCase(objFSO.GetExtensionName(f))
  If (ext = "mdb" Or ext = "mdd" Or ext = "vei") And LCase(Left(f.Name, 5)) = "dados" Then
    f.Copy "C:\BCK\dados\"
  End If
Next
另一个(可能更简单)选项是使用正则表达式检查文件名:

Set re = New RegExp
re.Pattern = "^dados.*\.(mdb|mdd|vei)$"
re.IgnoreCase = True

For Each f In objFSO.GetFolder("C:\Folder1").Files
  If re.Test(f.Name) Then f.Copy "C:\BCK\dados\"
Next

我尝试并制作了一个vbscritp来调用批处理,但我需要在vbscript中包含所有内容…我不太理解vbscript语言…这是一个简单的工作安装。向我们展示您的尝试,然后我们可以帮助您使其工作。请不要在注释中发布代码。改为编辑您的问题。此外,您拥有的是批处理代码,而不是VBScript代码。在VBScript中封装批处理代码是可能的(使用or方法),但我不建议将其用于您描述的任务。要么坚持批处理,要么在正确的VBScript中重新实现它。我真正需要的是在VBScript代码中实现它…但我以前说过…我从未在VBScript中做过任何事情…首先:停止(重新)一遍又一遍地创建
objFSO
。创建它一次,然后不去管它。至于错误,如果您的问题是当
CopyFile
找不到匹配的文件时脚本以错误终止,那么您可以将复制说明放在错误恢复下一步的
和错误转到0的
之间。请注意,这将掩盖所有错误。如果需要检测除“无此类文件”以外的错误情况,则需要添加错误处理代码。否则,您可以使用我的答案中描述的循环。