ZipForge: how to add Empty folder to archive? - delphi

Question in the title.
I didn't manage to find a way to add an empty folder to the archive or create an empty directory inside of the archive.
It works fine if I just add files and folders by mask, but I have to add files one by one and not all together (there are reasons).
How can I create an empty directory inside archive?

I've found a way to create empty folder more correctly.
As David Heffernan stated, we should add empty file titled as our folder:
FullFolderName = 'foo\bar'
ZipForge.AddFromBuffer(FullFolderName, nil^, 0);
Note: bar is our empty folder which should be in the foo folder. Do not put backslash at the end of the path.
And after that we should change the attribute of the "folder" inside the archive, because our "folder" has the same attribute as a file. To do this we should call:
ZipForge.ChangeFilesAttr(FullFolderName, ZFDirectoryAttr);
ZFDirectoryAttr is a constant declared in ZipForge.pas and equals to 16.

ZIP files do not explicitly support the concept of folders. Instead you specify file names with path separators, and ZIP file tools infer the intended structure that way.
So the way you fake an empty folder is to create an empty file with a name that ends in a trailing path separator.
I don't know ZipForge, but in the built in TZipFile you'd do it like this:
ZipFile := TZipFile.Create;
try
ZipFile.Open('C:\desktop\temp.zip', zmWrite);
ZipFile.Add(TBytes(nil), 'foo/');
finally
ZipFile.Free;
end;

Related

Erlang : exception error: no match of right hand side value {error,enoent} while reading a text file

I am currenly working on an erlang project and stuck in reading the file. I want to read a text file which is in the /src folder where all the erlang and a text file are in the same structure. Then too, I am not being able to read the file despite of specifying file paths. Any help would be appreciated.
start() ->
{ok,DataList} = file:consult("Calls.txt"),
io:format("** Calls to be made **"),
io:fwrite("~w~n",[DataList]).
The data file stores contents like : {john, [jill,joe,bob]}.
Try add folder name to the path or try set full patch to the file:
1> {ok,DataList} = file:consult("src/Calls.txt").
Notes: the error {error,enoent} mean that the file does not exist or you don't have a rights to read/write current file, for this case need set 777 rights or similar.
If you need to use src/call.txt, then this simply means that your IDE (or you) has created a src folder in which the calls.txt file has been placed. At the same time, the IDE is using a path that only includes the top level folder (i.e., the root folder for the IDE project). So src/call.txt must be used in that case. This isn’t a problem with Erlang, or even the IDE. It’s just the way your project is set up.
You can do either of two things. Move the calls.txt file up one level in the IDE file manager, so that it can be referenced as calls.txt, not src/call.txt. You can also just change the path to “calls.txt” before you run it from the command line.
enoent means "Error: No Entry/Entity". It means the file couldn't be found. When I try your code, it works correctly and outputs
[{john,[jill,joe,bob]}]

How do I create a path in code to locate a file in a specific location? Delphi XE6?

What is the procedure or method add a path to a file in the {$I ...} line?
I have a file that I want the compiler to be able to find.
For example, say I have downloaded a file named "abc.inc" that receives a file error as follows:
F1026 File not found: 'abc'
The file in code is something like this:
{$I abc.inc}
My question is how do you write a file path in code to a particular folder in my project?
For example, let's say my file "abc" is located this path: project\comps\jcl\abc.inc
How would I write in code {$I abc.inc} "is located in path comps\jcl\abc.inc ?
I think I know how {$I functions... How to add/include/incorporate "abc.inc" file into my project using code. How do I write a path in code?
The answer can be found in the documentation:
If the filename does not specify a directory path, then, in addition to searching for the file in the same directory as the current module, Delphi searches in the directories specified in the Search path input box on the Delphi Compiler page of the Project > Options dialog box.
This documentation text is vague at best. What actually happens if you specify a relative path, is that the path is taken to be relative to the file which contains the $INCLUDE directive.
So if the file to be included is not in the same directory as the source file that is including it then your options are to:
Specify the absolute path of the include file, or
Specify the path of the include file, relative to the source file containing the $INCLUDE directive, or
Add the directory containing the include file to the search path.

tfignore wildcard directory segment

Is it possible using .tfignore to add a wildcard to directories? I assumed it would have been a case of just adding an asterisk wildcard to the directory segment. For example:
\path\*\local.properties
However this does not work and I am unsure how I would achieve such behaviour without explicitly declaring every reference that I need excluding. .
Documentation
# begins a comment line
The * and ? wildcards are supported.
A filespec is recursive unless prefixed by the \ character.
! negates a filespec (files that match the pattern are not ignored)
Extract from the documentation.
The documentation should more correctly read:
The * and ? wildcards are supported in the leaf name only.
That is, you can use something like these to select multiple files or multiple subdirectories, respectively, in a common parent:
/path/to/my/file/foo*.txt
/path/to/my/directories/temp*
What may work in your case--to ignore the same file in multiple directories--is just this:
foo*.txt
That is, specify a path-less name or glob pattern to ignore matching files throughout your tree. Unfortunately you have only those two options, local or global; you cannot use a relative path like this--it will not match any files!
my/file/foo*.txt
The global option is a practical one because .tfignore only affects unversioned files. Once you add a file to source control, changes to that file will be properly recognized. Furthermore, if you need to add an instance of an ignored name to source control, you can always go into TFS source control explorer and manually add it.
It seems this is now supported
As you see I edited tfignore in the root folder of the project such that any new branch will ignore its .vs folder when being examined for source control changes
\*\.vs
Directory/folder name wildcarding works for me in VS2019 Professional. For example if I put this in .tfignore:
*uncheckedToTFS
The above will ignore any folder named ending with "uncheckedToTFS", regardless of where the folder is (it doesn't have to be top level folder, can be many levels deep).

Copy from CSV and Rename in MS-DOS

I have a .csv file with the following format:
<path_including_filename>,<new_filename>
<path_including_filename>,<new_filename>
<path_including_filename>,<new_filename>
<path_including_filename>,<new_filename>
I want to copy what's on column #1 in my CSV from Location A to Location B, then rename the file on Location B with the content of the column #2 in my CSV.
This is what I have done so far, the copying works but the renaming seems doesn't really happen:
For /F "tokens=1* delims=," %%i in (myCSV.csv) do (copy "%%i" "C:/myFolder" && rename "C:/myFolder/%%~nxi" "%%j")
Thanks in advance.
This answer used to contain my wrong suggestion from comments:
When the second column isn't a full pathname, but just a file name, rename "C:/myFolder/%%~nxi" "%%j" takes its destination argument as a path relative to current directory, not to the source directory.
I thought the problem should be solved by providing a full path name in the second argument of rename as well:
rename "C:/myFolder/%%~nxi" "C:/myFolder/%%j"
But no: the full path name is actually invalid in the destination argument for rename. The solution of cding to the target directory first and renaming without folder names in either argument turned out to work. I think that replacing forward slashes with backslashes in the first argument (leaving the second without the folder name) would help too: in my tests on Windows XP, rename failed with "file not found" when a source folder path contained forward slashes, and worked for backslashes.

How do I find a specific entry inside a zipped directory using the rubyzip gem?

I have a zip file named test.zip which contains a directory named invoice. Inside the invoice directory there are documents each with different names. I would like to find a specific document named summary.txt which is inside the invoice directory.
I am able to get a handle to test.zip using the following:
zip = Zip::ZipFile.open("/path/to/test.zip")
but when I use
zip.find_entry("summary.txt")
I get nil.
On the other hand, if summary.txt is not inside the the invoices directory, but rather at the root of the zip file itself, the find_entry method as described above seems to work.
It seems that somehow I must navigate down into the invoices directory before searching for summary.txt.
Is this correct? If so, how do I do it? If not, what I am I doing wrong.
You need to specify the full path to the file:
zip.find_entry 'invoices/summary.txt'

Resources