i'd like to zip everything except one file
7z a -tzip files.zip *
this will zip all the files in my current directory.. is there a way I can tell it to not zip one file or one file type ?
i'd like to zip everything except one file
7z a -tzip files.zip *
this will zip all the files in my current directory.. is there a way I can tell it to not zip one file or one file type ?
Per the 7za command-line help, you use the -x switch to do this:
-x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames
To exclude the file foo.txt you would add:
-x!foo.txt
To exclude all .html files (*.html) you would add:
-x!*.html
You can add multiple -x entries to exclude multiple filenames and/or wildcards in one zip command. Adding the following will exclude foo.txt and *.html:
-x!foo.txt -x!*.html
So with your example, this would add all files to files.zip EXCEPT files named "FILENAME" or that matched the *.extension wildcard:
7z a -tzip files.zip * -x!FILENAME -x!*.extension
"-xr!.git\"
and "-xr!.gitignore"
. Note the double quotes ("
) as mentioned by @ChrisKolenko. –
Monarch If you are using batch script do not forget to escape ! mark.
7z a -xr^^!*.xml "dest_dir.zip" "Source_dir"
For excluding individual files or wildcard entries, the command line option does not seem to work. Instead list the files to be excluded and wild cards in text file (..\xlist.txt) and specify it in the comand line like this:
7z a -tzip files.zip * -xr@..\xlist.txt
Specify xlist.txt using relative path.
xlist.txt itself if you dont want it
index*
*.js
*.tmp
etc...
This fragment of a larger (linux bash) 7z-script (with password compression, adjustable LEVEL setting etc) excludes the script file itself, also when dirs need to be compressed.
The ${INPUT} comes from:
echo "Your Input please?"
read -e -p "" INPUT
and can be a simple '*' wildcard to refer to all files and dirs.
Fragment:
for FILE in ${INPUT}
do
if [[ ${FILE} != my_7z_script.sh ]]
then
7z a -mx=${LEVEL} -mhe -t7z ${FILE%.*}.7z ${FILE} -x!my_7z_script.sh
fi
done
Could probably leave the '-x!my_7z_script.sh' out, but kept it in anyway. If the file name of the script is long, you can also use an asterix wildcard there, e.g.: 'my_7z*.sh'.
Addendum, the above makes separate 7z's of every file and folder. To convert/compress all files and dirs (within the dir of the script, except the script itself) to 1 7z:
echo "The Final 7z Destination of your Input please (without 7z-extension)?"
read -e -p "" DESTINATION
for FILE in ${INPUT}
do
if [[ ${FILE} != my_7z_script.sh ]]
then
7z a -mx=${LEVEL} -mhe -t7z ${DESTINATION}.7z ${INPUT} -x!my_7z_script.sh
fi
done
'*' wildcard for all files and dirs input, exclusive hidden ones (.hidden), '.' wildcard for all files and dirs input, inclusive hidden ones.
Maybe room for improvements, but it seems to work.
(P.S.: the ${LEVEL} var isn't specified here. You can replace it with anything from '0' aka 'store only' to '9' aka 'high compression'.)
© 2022 - 2024 — McMap. All rights reserved.
-x!*.extension
doesn't work (at least for recursive sub-directories).-x!*extension
does work. – Barriebarrientos