NSIS copy subfolders and files in them to install dir - nsis

With this it will copy all files from res folder,
SetOutPath "$INSTDIR"
File "res\"
but I need to copy all subfolders and files in them.
How can I achive that.

The manual is very clear, use File /r "yourfolder" to copy the whole directory tree...

Related

unzip in current directory while preserving file structure

I'm in a directory and I have a zip containing files and directories.
I need to unzip that file, into current directory, but preserving the file structure.
unzip myfile.zip will create a myfile directory in current directory which is not what I want.
unzip -j myfile.zip will kill all the file strucure, which is not what I want.
unzip myfile.zip extracts files in the working directory by keeping path names from the zip file.
So if you get a subdirectory myfile it means it is part of the relative path of compressed files. Check it by listing the zip content
unzip -l myfile.zip
So you can unzip the file from the directory above, or, from the target directory unzip with -d option, where -d is the directory above
cd myfile
unzip myfile.zip -d ..
Dont select the folder while zipping.
For example
myfile/abc.txt and myfile/efg.txt
so while zipping select the files (abc.txt,efg.txt) and zip dont select the myfile folder to zip.
So that when you unzip the file, the parent dir for each file or folder will be the directory in which you unzip.
The myfile directory was zipped into the zip file when it was created and looking at the unzip options there isn't a way to do this without adding additional steps.
If this entire process is under your control you should look at either creating the zip without using including the parent directory or you could use an alternative like tar (to create and extract) which allows you to extract content from the repo with greater precision.

Create tar.gz archive and add all files and folders without parent folder

For example i have folder "admin" which contains folder "1" and two php files "index.php" and "page.php". I try to use tar -zcvf admin.tar.gz admin and got admin.tar.gz archive. If i open this archive, i can see archive contains "admin" folder and inside this directory is folder "1" and two php files.
I want to create tar.gz archive with all files and folders, but without parent folder. Create archive and it contains only folder "1" and two php files. How i can do it?
You can use the -C option:
tar -C admin -zcvf admin.tar.gz .
See man tar
-C, --directory=DIR
Change to DIR before performing any operations.
This option is order-sensitive, i.e. it affects all options that follow.

Linux - how to rename files within a .tgz file without extracting contents and applying tar again?

I have a tar file called test.tgz , inside it are the following files:
tool.foo
atest.you
btest.you
ctest.you
t.you
I want to rename the files inside test.tgz to be:
0.foo
0.you
1.you
2.you
3.you
Without the use of extracting the files and repacking them. How could I accomplish this?
Even though you can't rename the files in the tar archive, you can rename them with a sed expression on the fly while they are being extracted. The option to tar is--transform [sed-expression].
You do need to extract the files before you rename them. When files are in a tgz, they are protected from change.

How to rename files according to other files?

I have several files in a folder with extension .img and I have only one file with extension data.txt
What I need is to copy data.txt and rename it as the names of the .img files.
For instance for the first file in my folder:
`Meaurmen_2154_data.img` >>> copy data.txt >>> rename it Meaurmen_2154_data.txt
Now I have :
Meaurmen_2154_data.img
Meaurmen_2154_data.txt ## the content is the same as data.txt
and do the same for all other files. The content of he text files will be the same for all files just we change the name according to the .img files in my folder.
Run this script
#!/bin/bash
imageFiles=( *.img );
for i in ${imageFiles[*]}
do
withoutExtension=${i%.img};
cp data.txt "$withoutExtension.txt";
done
inside the relevant directory and it will do it for you.
Try
for i in *.img; do cp data.txt $i.txt; done
rename 's/.img.txt/.txt/' *.img.txt
In some distro's rename is different, requiring
rename .img.txt .txt *.img.txt
As always, you might find yourself in need of installing additional packages.

How do you check what files are inside an NSIS setup.exe?

In my NSIS script, I use this line:
File "..\help\*.*"
My problem is that I have the help directory in my subversion repository (its constantly updated as we add new functionality). This means that the help directory contains a .svn directory.
I wish to view the contents of the setup.exe that NSIS created to verify that it does not have the .svn directory.
P.s. I experimented to see if NSIS recursively adds files when wildcards are used. It doesn't. But I want to verify this, hence the question.
These things are typically compressed files.
You could check with 7z/7-zip to open the EXE archive.
As a record, after the comments below,
I'd like to point to my recent notes on the merits of 7-zip at Superuser,
Compressing with RAR vs ZIP
Rather than look at what's in your NSIS exe itself, just exclude the .svn directories so you know they'll never be in there.
Something like this will do the trick:
File /r /x .svn "..\help\*.*"
The /x .svn bit tells NSIS to exclude those directories.
Coincidentally, if you're not using the /r switch, then you're not adding files and folders recursively, so it wouldn't add the .svn subdirectories anyway.
Instead of unzipping, my suggestion is to look at the NSIS compilation log. It will tell you everything about files included. When doing changes in my NSIS scripts I always check the logs to make sure that everything is going according to plan. Streaming the log from the command line to a text file, then read it from your favorite editor.
I use 7zip File Manager and the "Open Inside" command.

Resources