File io 使用添加的时间戳备份一段时间,并在循环中删除原始文件
代码的主要部分在手动启动时可以工作,但在我使用外部程序启动时不能工作,所以我觉得全自动启动更好 当我添加了几行以在备份后删除文件并循环(代码中标记为pt1、pt2、pt3)时,我得到了以下语法错误:File io 使用添加的时间戳备份一段时间,并在循环中删除原始文件,file-io,vbscript,File Io,Vbscript,代码的主要部分在手动启动时可以工作,但在我使用外部程序启动时不能工作,所以我觉得全自动启动更好 当我添加了几行以在备份后删除文件并循环(代码中标记为pt1、pt2、pt3)时,我得到了以下语法错误: Line: 66 Char 1 Syntax Error 800A03EA MS VBscript compilation error 作为参考,这些是我检查和复制的链接: “------------------------------------添加代码pt1的开始” 做 “-----
Line: 66
Char 1
Syntax Error
800A03EA MS VBscript compilation error
作为参考,这些是我检查和复制的链接:
“------------------------------------添加代码pt1的开始”
做
“-------------------------------------添加代码pt1的结尾”
Dim objFSO
暗箱文件夹
Dim sDestFolder
Dim SDB文件
暗色时间戳
写入文件上的常数=真
设置objFSO=CreateObject(“Scripting.FileSystemObject”)
sSourceFolder=“C:\Program Files\N H P”
sBackupFolder=“C:\Program Files\N H P\ArchiveData”
sDBFile=“N-H-P”
sDBFileExt=“csv”
sDateTimeStamp=cStr(年份(现在)()&
Pad(cStr(月份(现在))、2)和
Pad(cStr(日(现在))、2)和
Pad(cStr(小时),2)和
Pad(cStr(分钟(现在()),2)
'如果备份文件夹不存在,请创建它。
如果不存在objFSO.FolderExists(sBackupFolder),则
objFSO.CreateFolder(sBackupFolder)
如果结束
'只要可以找到文件,就复制该文件
如果存在objFSO.files(sSourceFolder&“\”&sDBFile&“&sDBFileExt),则
objFSO.CopyFile sSourceFolder&“\”&sDBFile&“&sDBFileExt,\u
sBackupFolder&“\”&sDBFile&“\”&sDateTimeStamp&“&sDBFileExt,\u
超写文件
如果结束
设置objFSO=Nothing
功能板(CStr2Pad,要求)
暗Num2Pad
Pad=CStr2Pad
如果len(CStr2Pad)
这里的问题是在Do循环中。您尝试在循环中声明一个新函数。我真的建议您对代码进行更多的格式化,这样更容易发现错误。还有一个记事本编辑器,具有可视大括号匹配(Notepad2、notepad++等)帮助。这是格式化和修复的代码,尽管我没有测试实际的复制、删除
Dim objFSO
Dim sSourceFolder, sDestFolder, sDBFile, sDateTimeStamp
Const OVER_WRITE_FILES = True
Do
Set objFSO = CreateObject("Scripting.FileSystemObject")
sSourceFolder = "C:\Program Files\N H P"
sBackupFolder = "C:\Program Files\N H P\ArchiveData"
sDBFile = "N-H-P"
sDBFileExt = "csv"
sDateTimeStamp = cStr(Year(now())) & _
Pad(cStr(Month(now())),2) & _
Pad(cStr(Day(now())),2) & _
Pad(cStr(Hour(now())),2) & _
Pad(cStr(Minute(now())),2)
'If the backup folder doesn't exist, create it.
If Not objFSO.FolderExists(sBackupFolder) Then
objFSO.CreateFolder(sBackupFolder)
End If
'Copy the file as long as the file can be found
If objFSO.FileExists(sSourceFolder & "\" & sDBFile & "." & sDBFileExt) Then
objFSO.CopyFile sSourceFolder & "\" & sDBFile & "." & sDBFileExt,_
sBackupFolder & "\" & sDBFile & "_" & sDateTimeStamp & "." & sDBFileExt,_
OVER_WRITE_FILES
End If
'Delete the file as long as the file can be found
If objFSO.FileExists(sSourceFolder & "\" & sDBFile & "." & sDBFileExt) Then
objFSO.DeleteFile sSourceFolder & "\" & sDBFile & "." & sDBFileExt,_
OVER_WRITE_FILES
End if
Set objFSO = Nothing
WScript.Sleep 50000
Loop
Function Pad(CStr2Pad, ReqStrLen)
Dim Num2Pad
Pad = CStr2Pad
If len(CStr2Pad) < ReqStrLen Then
Num2Pad = String((ReqStrlen - Len(CStr2Pad)), "0")
Pad = Num2Pad & CStr2Pad
End If
End Function
Dim objFSO
Dim sSourceFolder、sDestFolder、sDBFile、sDateTimeStamp
写入文件上的常数=真
做
设置objFSO=CreateObject(“Scripting.FileSystemObject”)
sSourceFolder=“C:\Program Files\N H P”
sBackupFolder=“C:\Program Files\N H P\ArchiveData”
sDBFile=“N-H-P”
sDBFileExt=“csv”
sDateTimeStamp=cStr(年份(现在)()&
Pad(cStr(月份(现在))、2)和
Pad(cStr(日(现在))、2)和
Pad(cStr(小时),2)和
Pad(cStr(分钟(现在()),2)
'如果备份文件夹不存在,请创建它。
如果不存在objFSO.FolderExists(sBackupFolder),则
objFSO.CreateFolder(sBackupFolder)
如果结束
'只要可以找到文件,就复制该文件
如果存在objFSO.files(sSourceFolder&“\”&sDBFile&“&sDBFileExt),则
objFSO.CopyFile sSourceFolder&“\”&sDBFile&“&sDBFileExt,\u
sBackupFolder&“\”&sDBFile&“\”&sDateTimeStamp&“&sDBFileExt,\u
超写文件
如果结束
'只要可以找到文件,就删除该文件
如果存在objFSO.files(sSourceFolder&“\”&sDBFile&“&sDBFileExt),则
objFSO.deletefilessourcefolder&“\”&sDBFile&“&sDBFileExt,\u
超写文件
如果结束
设置objFSO=Nothing
WScript.Sleep 50000
环
功能板(CStr2Pad,要求)
暗Num2Pad
Pad=CStr2Pad
如果len(CStr2Pad)
Dim objFSO
Dim sSourceFolder, sDestFolder, sDBFile, sDateTimeStamp
Const OVER_WRITE_FILES = True
Do
Set objFSO = CreateObject("Scripting.FileSystemObject")
sSourceFolder = "C:\Program Files\N H P"
sBackupFolder = "C:\Program Files\N H P\ArchiveData"
sDBFile = "N-H-P"
sDBFileExt = "csv"
sDateTimeStamp = cStr(Year(now())) & _
Pad(cStr(Month(now())),2) & _
Pad(cStr(Day(now())),2) & _
Pad(cStr(Hour(now())),2) & _
Pad(cStr(Minute(now())),2)
'If the backup folder doesn't exist, create it.
If Not objFSO.FolderExists(sBackupFolder) Then
objFSO.CreateFolder(sBackupFolder)
End If
'Copy the file as long as the file can be found
If objFSO.FileExists(sSourceFolder & "\" & sDBFile & "." & sDBFileExt) Then
objFSO.CopyFile sSourceFolder & "\" & sDBFile & "." & sDBFileExt,_
sBackupFolder & "\" & sDBFile & "_" & sDateTimeStamp & "." & sDBFileExt,_
OVER_WRITE_FILES
End If
'Delete the file as long as the file can be found
If objFSO.FileExists(sSourceFolder & "\" & sDBFile & "." & sDBFileExt) Then
objFSO.DeleteFile sSourceFolder & "\" & sDBFile & "." & sDBFileExt,_
OVER_WRITE_FILES
End if
Set objFSO = Nothing
WScript.Sleep 50000
Loop
Function Pad(CStr2Pad, ReqStrLen)
Dim Num2Pad
Pad = CStr2Pad
If len(CStr2Pad) < ReqStrLen Then
Num2Pad = String((ReqStrlen - Len(CStr2Pad)), "0")
Pad = Num2Pad & CStr2Pad
End If
End Function