Zipping a folder - delphi

I am trying to use
TZipFile.ZipDirectoryContents()
Like so:
TZipFile.ZipDirectoryContents('Test.PCF', WorkingDir);
If I am reading this right, it should save the contents of folder "workingdir" into a file named Test.pcf.
Now when I do this I get error::
Raised exception class EFOpenError with message Cannot open file
...test.pcf. The process cannot access the file because its being used by another process."
Two things confuse me:
It says that it cannot open file. There is no test.pcf yet. I was hoping this would create it.
It says cannot access file. Is this because it's not created yet? Am I using this function wong? If so how would I create a zip file from a folder location?

I tested your code and it failed in the same way as you reported.
I then created an empty zip file manually by running WinZip.
Then ran your code and it ran fine.
It appears that the zip file has to already exist for ZipDirectoryContents to work.
To create a zip file programatically:
myZipFile := TZIpFile.Create;
myZipFile.Open('c:\myfolder\newzipfile.zip', TZipMode.zmWrite);
myZipFile.Close;
myZipFile.Free;
This line will then work:
TZipFile.ZipDirectoryContents('c:\myfolder\newzipfile.zip', WorkingDir);

Related

Module build failed (from ./node_modules/#ngtools/webpack/src/index.js):

I have created an application on angular 7 and ionic 4.
I tried to edit app.routing.ts file, setting path and component. From then on I am getting this error below:
ERROR in ./src/app/department/department.module.ts
[ng] Module build failed (from ./node_modules/#ngtools/webpack/src/index.js):
[ng] Error: ENOENT: no such file or directory, open 'C:\Users\x\department\department.module.ts'
[ng] at Object.openSync (fs.js:436:3)
[ng] at Object.readFileSync (fs.js:341:35)
[ng] at Storage.provideSync (C:\Users\x\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:98:13)
Make sure department component exist, check the templateUrl that corresponds to the file name you are referencing. You may have also modified the path unknowingly during modification of app.routing.ts file.
C:\Users\x\department\department.module.ts
This error occurs when your component can't be found with your app.module settings.
Follow these steps to solve your problem:
Check if the module.ts file exists.
Check the relative path.
The path is case sensitive (maybe the .ts file is Department).
Both answer are useful from #trustidkid and #vinay sharma. If there is someone has been facing the same problem;
1-Go to to the file that the error has occurred in. (To go directly to the file, click the error line shortly [CTRL+Click] (CMD+Click on MacOS):
ERROR in ./src/app/department/department.module.ts
Then check the path address if it is exactly true pointing the file. Most of these problems are having similar solutions. Just be sure about the path address of the file you want to point and the address mentioned in the other file which the error occurred.
This problem happens when you delete a component but forgot to delete its import from module.ts.
For example: TestComponent is deleted so you have to also delete:
import { TestComponent } from './test.component'
If you have a folder mapping on a windows machine like me, do not try to build it from a mapped folder, go to the original folder and build it from there.
Mapped Folder has a small icon like this:
In my case I had prime ng version that did not support a particular module, I simply commented it out and it worked.

how to replicate "WEB-INF/resources/apps/xbl/orbeon/us-state"

I try replicate the example with file "zip-states.xpl" in diretory "WEB-INF\resources\apps\xforms-sandbox\services" and files directory /WEB-INF/resources/apps/xbl/orbeon/us-state.
In my case, the first file (zip-states.xpl),I changed the value from select="doc('/xbl/orbeon/us-state/states.xml')/states/state to select="doc('/xbl/orbeon/colombia/states.xml')/states/state.
After, I copied the files from "apps/xbl/orbeon/us-state" to "apps/xbl/orbeon/colombia", and change file name us-state.xbl to colombia.xbl
In file colombia.xbl, I changed value from "src="oxf:/xbl/orbeon/us-state/state.xml" to src="oxf:/xbl/orbeon/colombia/state.xml" and I go to the test form , but its not working.
I try created the same case, for change the value in state.xml for colombia states but in other file.
Please, I hope you can help me
Many thanks.

Remove zip file item path with Abbrevia

Is it possible to remove a zip file item's path with Abbrevia? After looking at the source code I can not find a method to remove the path of a file. Has anyone tried to do this and if so, how?
EDIT
I am displaying the contents of a zipfile in a TAbListView where the path for each file is stored in the archive. The items were added to the zip file with the StoreOptions set at [soStripDrive], so the path is stored in the TAbListView.Items.Item[I].Subitem[9] for each file in the zip file. I am looking to strip the paths and then save the archive so that none of the files have paths.
Paths before removal
TAbListView.Items.Item[0].Subitem[9] := \DelphiXE4\Projects\Abbrevia\Unit1.pas
TAbListView.Items.Item[1].Subitem[9] := \DelphiXE4\Projects\Abbrevia\Unit1.dfm
Paths after removal
TAbListView.Items.Item[0].Subitem[9] := '';
TAbListView.Items.Item[1].Subitem[9] := '';
So the zipped items do not have any paths.
AFAICT, you can't change the name in the archive (zip) without actually extracting the file and then putting it back in without storing the path in the first place.
The obvious place to try and change it would be with TAbZipItem.StoredPath, but that's read only; using TAbZipItem.FileName works fine when compiling and running, but has no effect. Nothing you do in the TAbsListView will change anything, as it's just displaying content and has nothing to do with the underlying zip archive.

XNA error - file not found

I am working on XNA with XML reading. While I'm debugging the code its shows file not found error, but I added my XML file in Content reference folder. While I'm using this code I got the error.
System.IO.Stream stream = TitleContainer.OpenStream("ProductSchema");
Thanks in advance.
Bharathi.G
Shawn explains this very well in this post: Shawn's blog entry
Try adding the extension:
System.IO.Stream stream = TitleContainer.OpenStream("ProductSchema.xml");
Check whether that file is present in the bin folder where your game .exe file lives (bin\Windows Phone\Debug\Content). If not, then this may be the problem. To solve this :
right click the file >> select property >> change build action to None and copy to output directory to Copy if newer.
This works for me while loading/reading binary files in my game.

how to get a static file (.json) palced in myapp/apps/myapp/jsons/ through SC.Request.getUrl

My sprout core app name is myapp. My directory structure is myapp/apps/myapp/.
I have created a directory named jsons inside myapp/apps/myapp/, and placed a file called emp.json, I want to get this file through ajax using SC.Request.getUrl. I tried the following but didn't work. I want to know the url to reach out this file.
SC.Request.getUrl('/myapp/apps/myapp/resources/emp.json').notify(this, this.didFetchContacts)
.send();
SC.Request.getUrl('/myapp/resources/emp.json').notify(this, this.didFetchContacts)
.send();
Thanks
Ok, you will need to use static_url. So if emp.json is in your resources directory, you can call this:
SC.Request.getUrl(static_url('emp.json')).notify(this, this.didFetchContacts)
.send();
NOTE: This is not a javascript function. The compiler will replace this with the location of the file in the built app

Resources