Delphi function, Not allowing files and folders from main directory during compression

安稳与你 提交于 2019-12-02 13:36:30

The code already employs a technique for skipping certain unwanted file names:

if (sr.Name <> '.') and (sr.Name <> '..') then

Simply use that same technique to exclude whatever other files you wish. You can hard-code the exclusion list into the code, as is already done with the . and .. names, or you can pass a list of names into the function as another parameter. Before you add a file to the archive, check whether that file name is in the list of files to exclude.

For example, if the list of excluded names were in a TStrings descendant, you might use something like this:

if ExcludedNames.IndexOf(sr.Name) >= 0 then
  Continue; // Skip the file because we've been told to exclude it.

You could enhance this to check the full path of the file instead of just the local name. You could also enhance it to support wildcards in the list of exclusions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!