|
-
Mar 8th, 2025, 01:07 PM
#1
Thread Starter
Fanatic Member
Does it make sense to copy a project to a "safe location" before zipping it?
Hello everyone,
In the past, I used 7zip to regularly back up my projects. Now, I am using a slightly customized version of wqweto's ZipArchive class:
https://github.com/wqweto/ZipArchive
I prefer this class because I can compile it myself, which means I no longer have to assume the source is safe—I know it is. That is a huge benefit! Thank you!
7zip used to throw errors when encountering locked files, particularly with some .NET-specific Visual Studio files. Because of that, I developed the habit of copying all project files to a safe location before zipping them.
This gave me confidence that I could continue working in VB6 and experimenting while the zipper archived the last functional version. But I am now questioning if this approach actually makes sense. Over the years, I have become a bit paranoid...
This is not just a theoretical question—I am currently in the process of rewriting my backup solution. Since I have recently started using RC6 threading, I wonder whether my "copy to safe location" approach is necessary or if I should simply skip locked files. If I stick with this habit, I would use RC6 threading for copying files, making the project more complex.
Before doing that, I would like to hear opinions from others on whether this is a good approach.
Currently, I am using SHFileCopy, which is blocking, which is why I was considering RC threading to allow easy cancellation.
Update – Why I Initially Chose to Copy Files to a Temporary Location
I just remembered the real reason I originally started copying files to a temporary location before zipping. It was not only about avoiding locked files but also about ensuring a specific folder structure within the ZIP archive that retains the original path information.
For example, if my original project path was:
Code:
d:\dev\projects\MyProjectName
I would first copy the files to a temporary directory like this:
Code:
w:\tempremove\MyProjectName_2025.3.8.18.42\0001\d_\dev\projects\MyProjectName
Then, I would create the ZIP file:
Code:
MyProjectName_2025.3.8.18.42.zip
And inside that ZIP file, the folder structure would be:
Code:
d_\dev\projects\MyProjectName
This way, I could always reconstruct the original project path later without ambiguity.
Why Not Just Modify the Paths in the ZIP Directly?
I originally wanted to avoid physically copying the files and instead specify the target path inside the ZIP archive dynamically. However, I could not find a way to do this with wqweto’s ZipArchive class.
It seems that the only way to get the correct structure in the ZIP is to physically copy the files into the temporary structure first and then zip them from there.
If anyone knows a way to modify the stored paths inside the ZIP without having to physically reorganize the files first, I’d love to hear it!
The following function is how ZipArchive currently adds files to the archive. I need to modify it so that it enforces my custom folder structure without requiring the files to be physically moved first:
Code:
Private Function AddFile( _
file As Variant, _
Optional uFilepathOrDirectory As String, _
Optional uComment As String, _
Optional uPassword As String, _
Optional uEncrStrength As Long = cstEncrStrength, _
Optional uLevel As Long = -1) As Boolean
Const FUNC_NAME As String = "AddFile"
On Error GoTo EH
pvSetError
If pSkip(uFilepathOrDirectory) Then
Exit Function
End If
Dim nFile As ZipVfsType
Dim bIsOpen As Boolean
bIsOpen = pvVfsOpen(file, nFile)
If Not bIsOpen Then
Exit Function
End If
If m_lFileCount = 0 Then
ReDim m_Files(0 To 2) As ZipFileInfo
ElseIf m_lFileCount > UBound(m_Files) Then
ReDim Preserve m_Files(0 To 2 * UBound(m_Files)) As ZipFileInfo
End If
With m_Files(m_lFileCount)
If LenB(uFilepathOrDirectory) <> 0 Then
.FilepathOrDirectory = uFilepathOrDirectory
Else
.FilepathOrDirectory = Mid$(nFile.FilepathOrDirectory, InStrRev(nFile.FilepathOrDirectory, "\") + 1)
End If
If Right$(.FilepathOrDirectory, 1) = "\" Then
.Size = 0
.Attributes = vbDirectory
Else
.Size = pvToInt64(nFile.Data.nFileSizeLow, nFile.Data.nFileSizeHigh)
.Attributes = nFile.Data.dwFileAttributes
End If
m_BytesToProcessOverall = m_BytesToProcessOverall + .Size
.Comment = uComment
.LastModified = pvFromFileTime(nFile.Data.ftLastWriteTime)
.Extra = vbNullString
If IsObject(file) Then
'--- remove VT_BYREF if any
Set .SourceFile = C_Obj(file)
Else
.SourceFile = file
End If
.Level = uLevel
.Password = uPassword
.Aes.Strength = uEncrStrength
If Not nFile.SourceArchive Is Nothing Then
.FilepathOrDirectory = nFile.SourceFileInfo(zipIdxFilepathOrDirectory)
.Comment = nFile.SourceFileInfo(zipIdxComment)
End If
End With
m_lFileCount = m_lFileCount + 1
'--- success
AddFile = True
QH:
On Error Resume Next
pvVfsClose nFile
Exit Function
EH:
Debug.Print Err.Number
Debug.Print Err.Description
pvSetError MODULE_NAME & "." & FUNC_NAME & vbCrLf & Err.Source, Err.Description
Resume QH
End Function
I would really appreciate your thoughts on this!
Thank you very much!
Last edited by tmighty2; Mar 8th, 2025 at 01:32 PM.
-
Mar 8th, 2025, 01:40 PM
#2
Re: Does it make sense to copy a project to a "safe location" before zipping it?
It would be a lot easier, and less trouble in the long run, to just use some form of version control instead of trying to create your own solution.
Git is free https://git-scm.com/downloads and if you don't like using the command line there are guis you can use e.g.
https://tortoisegit.org/ and https://www.sourcetreeapp.com/ are two personal favourites of mine while https://git-scm.com/downloads/guis?os=windows has a list of various options.
Git will happily work locally without the need for a server etc. although if you do want such a thing then Azure Devops, github, bitbucket, and gitlab all offer free accounts.
-
Mar 8th, 2025, 11:47 PM
#3
Re: Does it make sense to copy a project to a "safe location" before zipping it?
See:
https://www.vbforums.com/showthread....ACZip-Archiver
I have used this simple program for over 10 years to Zip files for transport. You use the Common Dialog Control to select the desired files and copy them to a temporary directory in the users %temp% directory, and then select the ZIP file name and directory for creation. Once created, the temporary directory is deleted.
J.A. Coutts
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|