Giter Site home page Giter Site logo

Comments (7)

GustavBrock avatar GustavBrock commented on July 26, 2024

Path = "\server1\web"

Try with the normal UNC syntax:

Path = "\\server1\web"

from vba.compress.

unomasmas avatar unomasmas commented on July 26, 2024

My path is a typo, sorry. I tried with Path = "\\server1\web"

An added problem is that in the previous line, FileSystemObject.GetBaseName(Path) returns an empty string, so the name of the zip to generate will be ".zip", the value of the constant ZipExtension:

ZipName = FileSystemObject.GetBaseName(Path) & ZipExtension

from vba.compress.

unomasmas avatar unomasmas commented on July 26, 2024

I have not found a solution to get the name with FileSystemObject, so it is possible that there is a better solution than how I solved it. In my proposed solution It is also necessary to change line 1157 in the With ShellApplication block because the number of items will no longer be 1 (since the containing folder is not included in the zip) but the number of files and subfolders it contains. On the other hand, only non-empty folders are going to be included, so we need to find out how many there are. We need an additional function: getNumberOfEmptyFolders. I also add it.

This is the replacement for lines 1071 and 1072

If (FileSystemObject.GetDrive(FileSystemObject.GetDriveName(Path)).DriveType = Network) And FileSystemObject.GetFolder(Path).IsRootFolder Then
    If VBA.Right$(Path, 1) = "\" Then Path = VBA.Left$(Path, Len(Path) - 1)
    ZipName = VBA.Left$(Path, InStrRev(Path, "\")-1) & ZipExtension
    ZipPath = VBA.Mid$(Path, InStrRev(Path, "\")+1)
Else
    ZipName = FileSystemObject.GetBaseName(Path) & ZipExtension
    ZipPath = FileSystemObject.GetFolder(Path).ParentFolder
End If

This is the replacement for line 1157

Do Until .Namespace(CVar(ZipTemp)).Items.Count = (.Namespace(CVar(Path)).Items.count - getNumberOfEmptyFolders(.Namespace(CVar(Path)).Items)) Or Counter = 10

This is the additional function

#If EarlyBinding Then
Private Function getNumberOfEmptyFolders(fi As FolderItems) As Integer
    Dim item As FolderItem
#Else
Private Function getNumberOfEmptyFolders(fi As Object) As Integer
    Dim item As Object
#End If
    Dim iTmp As Integer
    
    For Each item In fi
        If item.isFolder Then
            If item.GetFolder.items.count = 0 Then
                iTmp = iTmp + 1
            End If
        End If
    Next item
    getNumberOfEmptyFolders = iTmp
End Function

from vba.compress.

GustavBrock avatar GustavBrock commented on July 26, 2024

Thank you! I also noted your question on SO: FileSystemObject: Retrieving folder name from UNC path.
The simple reason for the issue is, that I never tested the code with UNC paths. However, that's certainly a valid option to include, and I will look into it, but I can't tell when - it's quite busy here for the moment.

from vba.compress.

GustavBrock avatar GustavBrock commented on July 26, 2024

I checked with UNC paths for both source and destination, for both Zip/UnZip and Cab/DeCab, with files, folders, and with subfolders, but I cannot replicate your issue, sorry.
Fileshare was a Windows Server 2019 share.
Thus, I have to conclude, that the issue you experience is related to something else outside these functions.

from vba.compress.

unomasmas avatar unomasmas commented on July 26, 2024

Are you sure you did the tests with the parameters that I used? Initially I found the problem in Windows 10 but I just did tests in Windows Server 2019 and the result has been reproduced.

The problem only arises if the shared folder is the one you want to compress. If you try to compress a subfolder of the root folder there is no problem.

//Server/Folder will give problems
//Server/Folder/Subfolder will not give any problem.

from vba.compress.

GustavBrock avatar GustavBrock commented on July 26, 2024

Ah, I see. No, I didn't, but I did now, and - as you have found - it fails, because there is no parent folder.

However, that operation - to compress a fileshare root - is beyond the scope of the functions, as these are intended to work as closely to the behaviour in Windows Explorer as possible, and in Windows Explorer you can't zip/cab a fileshare, only a folder of a fileshare.
Thus, I've modified the functions to ignore the attempt to compress a fileshare.

from vba.compress.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.