您好我想使用vb6.0代码压缩文件。下面的代码实际上是在进行压缩部分。 但我想将系统日期添加到outputfilename。这没有发生。 任何人都可以建议
由于
Sub ZipAFile(filename, filepath, Optional outputFileName, Optional outputfilepath)
Dim d As String
filename = ABC.xls
filepath = App.Path & "\" & "New_Folder\"
d = Date
If Right(filepath, 1) <> "\" Then filepath = filepath & "\"
If IsMissing(outputFileName) Then
outputFileName = Left(filename, InStr(1, filename, ".") - 1) & ".zip"
Else
outputFileName = Trim(outputFileName) & ".ZIP"
End If
If IsMissing(outputfilepath) Then
outputfilepath = filepath
Else
outputfilepath = Trim(outputfilepath)
If Right(outputfilepath, 1) <> "\" Then outputfilepath = outputfilepath & "\"
End If
Shell "C:\Program Files\7-Zip\7z.exe a """ & outputFileName & """ """ & outputfilepath
End Sub
答案 0 :(得分:2)
您可以使用Format$
功能更改您认为合适的日期格式:
Sub ZipAFile(filename, filepath, Optional outputFileName, Optional outputfilepath)
Dim d As String
filename = ABC.xls
filepath = App.Path & "\" & "New_Folder\"
d = Format$(Now, "yyyymmdd") '// Change date formatting here
If Right(filepath, 1) <> "\" Then filepath = filepath & "\"
If IsMissing(outputFileName) Then
outputFileName = Left(filename, InStr(1, filename, ".") - 1) & d & ".zip" '// Append your date string
Else
outputFileName = Trim(outputFileName) & d & ".ZIP" '// Append your date string
End If
If IsMissing(outputfilepath) Then
outputfilepath = filepath
Else
outputfilepath = Trim(outputfilepath)
If Right(outputfilepath, 1) <> "\" Then outputfilepath = outputfilepath & "\"
End If
Shell "C:\Program Files\7-Zip\7z.exe a """ & outputFileName & """ """ & outputfilepath
End Sub
答案 1 :(得分:1)
可以创建没有第三方软件的zip文件(在你的情况下是7zip。)只是一个FYI。
Sub zip_a_file(path_to_target As String, _
file_with_extension_to_compress As String, _
zip_file_path As String, _
zip_file_name_without_extension As String)
Dim ZipFile
Dim o As Object
Dim d As String
'First, do a little bit of testing to see if the inputs are OK
If Right(path_to_target, 1) <> "\" Then
path_to_target = path_to_target & "\"
End If
If Right(zip_file_path, 1) <> "\" Then
zip_file_path = zip_file_path & "\"
End If
'Get the date and format it
d = Format(Now, "yyyymmdd")
'Create Empty Zip Package
ZipFile = zip_file_path & zip_file_name_without_extension & d & ".zip"
Open ZipFile For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
'Do some zippin'
Set o = CreateObject("Shell.Application")
o.Namespace(ZipFile).CopyHere (path_to_target & file_with_extension_to_compress)
'Clean up
Set o = Nothing
End Sub