
오래된 파일을 압축하고 삭제하는 스크립트가 있습니다. 스크립트는 다른 모든 디렉터리에서는 제대로 작동하지만 특정 디렉터리 하나는 작동하지 않습니다. 압축을 시도하지만 결국 Program.7z
. 이로 인해 스크립트에서 공백이 제대로 이스케이프되지 않고 있다고 생각됩니다. 내 경로에 큰따옴표와 작은따옴표를 사용하고 파일 경로의 연결을 확인했습니다. 나는 그것이 무엇인지 찾지 못했습니다. 어떤 아이디어가 있나요?
Const fileZillaLogs = "C:\Program Files (x86)\Server\Logs"
Const zipProgram = """C:\Program Files\7-Zip\7zG.exe"""
Const zipArgs = "a -mx9"
Dim intZipAge
intZipAge = 7
Dim intDelAge
intDelAge = 90
Call DeleteLogFiles(fileZillaLogs, intZipAge, intDelAge)
Function DeleteLogFiles(strLogPath, intZipAge, intDelAge)
Const bDEBUG = True
Dim objFs
Dim objFolder
Dim objSubFolder
Dim objFile
Dim objWShell
Dim strCommand
Dim iResult
Set objWShell = CreateObject("WScript.Shell")
Set objFs = CreateObject("Scripting.FileSystemObject")
If Right(strLogPath, 1) <> "\" Then
strLogPath = strLogPath & "\"
End If
If objFs.FolderExists(strLogPath) Then
Set objFolder = objFs.GetFolder(strLogPath)
For Each objSubFolder in objFolder.subFolders
DeleteLogFiles strLogPath & objSubFolder.Name, intZipAge, intDelAge
Next
For Each objFile in objFolder.Files
If bDebug Then wscript.echo vbTab & "reviewing file = " & strLogPath & objFile.Name
If DateDiff("d",objFile.DateLastModified,Date) > intDelAge Then
If bDebug Then wscript.echo "Deleting because its old" End If
objFs.DeleteFile(strLogPath & objFile.Name)
Else If DateDiff("d",objFile.DateLastModified,Date) > intZipAge _
And (Right(objFile.Name, 4) = ".log") Then
If bDebug Then wscript.echo vbTab & "zipping file = " & objFile.Path
strCommand = zipProgram & " " & zipArgs & " " & objFile.Path & ".7z" & " " & objFile.Path
iResult = objWShell.Run(strCommand, 0, "false")
If bDebug Then wscript.echo vbTab & "zipping result = " & iResult
If bDebug Then wscript.echo vbTab & "deleting file = " & strLogPath & objFile.Name
objFs.DeleteFile(strLogPath & objFile.Name)
End If
End If
Next
Set objFs = Nothing
Set objFolder = Nothing
Set objWShell = nothing
End If
End Function
답변1
문제는 41번 라인에 있습니다.obj파일.경로공백이 있지만 명령줄 인수에 추가하면 됩니다. 즉, 공백은 따옴표로 묶어야 하지만 따옴표는 문자열을 연결하는 데 사용되므로 사용할 수 없습니다. 그런 다음 최종 결과 문자열에 있어야 하는 따옴표를 이스케이프해야 합니다. VBS에서 이스케이프 문자는 큰따옴표 문자입니다. 따라서 41번째 줄은 다음과 같아야 합니다.
strCommand = zipProgram & " " & zipArgs & " " & """" & objFile.Path & ".7z" & """" & " " & """" & objFile.Path & """"
기본적으로 다음과 같이 계산되는 """" 시퀀스를 확인하세요.
- 첫 번째 큰따옴표: 문자열의 시작
- 두 번째 큰따옴표: 다음 문자를 이스케이프합니다.
- 세 번째 큰따옴표: 최종 문자열에 원하는 문자입니다.
- 네 번째 큰따옴표: 문자열 끝
테스트해봤는데 잘 작동합니다. 당신은 당신이 사용하는 두 시간 모두 탈출해야obj파일.경로기능.