I'm attempting to uncompress several .gz files using 7-Zip from the command line. My files are in directories like so:
Desktop/copyto/1/
file1.gz
file2.gz
Desktop/copyto/2/
file1.gz
file2.gz
file3.gz
I would like to recursively uncompress all the .gz files into each's orginal location and as well as deleting the remaining .gz files when they are done uncompressing.
I have tried the following command with no luck:
7z.exe x C:\Users\MYUSERNAME\Desktop\copyto\*\*.gz -r
I assumed that this would extract recursively. I get the error:
Processing archive: C:\Users\MYUSERNAME\Desktop\copyto\1\file1.gz
Can not open output file file1
Sub items Errors: 1
Any idea what's going on?
Given your command line, my guess is that your current working directory isn't any subdirectory of your home directory (C:\Users\MYUSERNAME) or the public user directory (C:\Users\Public), which means you probably don't have access rights. For example, if I run the following from C:\Program Files\7-Zip, I get the same error with a 7-Zip file:
C:\Program Files\7-Zip>7z x C:\Users\MYUSERNAME\Desktop\migrated\annex_k.7z -r
7-Zip [64] 9.38 beta Copyright (c) 1999-2014 Igor Pavlov 2015-01-03
Processing archive: C:\Users\MYUSERNAME\Desktop\migrated\annex_k.7z
ERROR: Can not open output file : .\annex_k\include\annex_k\errno.h
Skipping annex_k\include\annex_k\errno.h
ERROR: Can not open output file : .\annex_k\include\annex_k\handler.h
Skipping annex_k\include\annex_k\handler.h
...
Extracting annex_k\include\annex_k
Extracting annex_k\include
Extracting annex_k
Sub items Errors: 10
Archives with Errors: 1
Sub items Errors: 10
Kernel Time = 0.031 = 39%
User Time = 0.031 = 39%
Process Time = 0.062 = 78% Virtual Memory = 3 MB
Global Time = 0.080 = 100% Physical Memory = 4 MB
Notice that not even an annex_k directory was created:
C:\Program Files\7-Zip>dir /b
7-zip.chm
7-zip.dll
7-zip32.dll
7z.dll
7z.exe
7z.sfx
7zCon.sfx
7zFM.exe
7zG.exe
descript.ion
History.txt
Lang
License.txt
readme.txt
The solution is to extract to a directory in which you have access rights. You can specify an output directory using something like -oC:\Users\MYUSERNAME\Desktop\copyto\1. If you absolutely need to do this in a directory in which you don't have write access ordinarily, you'd need to run the command prompt as an administrator and extract the file as usual.
Related
We have an application in Oracle forms. From a form, we generate a .TXT file with some data. Now we are looking for options to generate a password protected file (preferrably zip file as .TXT cannot be password protected directly)
We use CLIENT_TEXT_IO to write data into file and close.
Is it possible to generate password protected zip file with CLIENT_TEXT_IO webutil?
U_IN_FILE := CLIENT_TEXT_IO.FOPEN (:M_FILE_PATH || 'some data.TXT','w');
CLIENT_TEXT_IO.PUT_LINE(U_IN_FILE,'some data');
CLIENT_TEXT_IO.FCLOSE (U_IN_FILE);
I presume you'd do that in two steps:
create .txt file the way you're already doing it
use CLIENT_HOST to invoke command-line ZIP utility and create a password-protected ZIP file
For example, on my MS Windows, using 7-zip, it would look like this:
c:\Temp\ZIP>"C:\Program Files\7-Zip\7z" a zipped_file.7z test.txt -pMARCH18
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
Scanning the drive:
1 file, 66 bytes (1 KiB)
Creating archive: zipped_file.7z
Add new data to archive: 1 file, 66 bytes (1 KiB)
Files read from disk: 1
Archive size: 202 bytes (1 KiB)
Everything is Ok
c:\Temp\ZIP>
ZIP command itself, explained:
7z a zipped_file.7z test.txt -pMARCH18
7z - invokes the utility
a - add to archive
zipped_file.7z - ZIP file name
test.txt - this is the file I'm going to ZIP
-pMARCH18 - password is MARCH18
Regarding the error calling Winzip, refer to these MyOracleSupport Notes:
1568659.1
1547133.1
In short, you will need to escape some of the characters in your call.
When using the zip file format to combine two parallel files, after data file upload we get the error message:
The document '._{name}_{lang}.txt' is not a valid {type} file as it contains one or more invalid characters.
The issue is that MacOS includes system files in the ZIP archive, and Microsoft tries to read them as data files because of the language suffix and .txt extension.
unzip -l data1.zip
Archive: data1.zip
Length Date Time Name
--------- ---------- ----- ----
0 04-09-2020 00:57 data1/
108746839 04-08-2020 23:55 data1/data_en.txt
120 04-08-2020 23:55 __MACOSX/data1/._data_en.txt
126795036 04-08-2020 23:56 data1/data_de.txt
120 04-08-2020 23:56 __MACOSX/data1/._data_de.txt
--------- -------
235542115 5 files
The fix is to compress them in a way that they are not added, or just remove them:
zip -d data1.zip __MACOSX*
zip -d data1.zip __DS_Store*
See https://apple.stackexchange.com/questions/239578/compress-without-ds-store-and-macosx, Mac zip compress without __MACOSX folder?...
Thanks to #ScottG for debugging.
I'm a newbie in windows scripting, so bear with me.
I want to find "test" folder from multiple folders. Such as
Search test folders from multiple paths:
/rbl.com/mailroot/test
/pml.com/mailroot/test
/pax.com/mailroot/
Want to get output like that:
test#rbl.com
test#pml.com
I have run this command to get results dir /S test > c:\results.txt
Output:
Volume in drive C has no label.
Volume Serial Number is 4A9E-06D4
Directory of C:\Program Files (x86)\Parallels\Plesk\Mail Servers\Mail Enable\Postoffices\rbl.com\MAILROOT
08/05/2016 12:36 AM <DIR> test
0 File(s) 0 bytes
Directory of C:\Program Files (x86)\Parallels\Plesk\Mail Servers\Mail Enable\Postoffices\pml.com\MAILROOT
08/05/2016 12:36 AM <DIR> test
0 File(s) 0 bytes
But how to extract the information like:
test#rbl.com
test#pml.com
This should do the trick
ls test -Directory -Recurse | % { "$($_.Name)#$($_.Parent.Parent.Name)" }
It searches your folders recursively for test folders, then prints out the folder's parent, its parent, and the folder's name as you want it formatted.
So, here's the problem: I have files which are regular files, and they are put into a ZIP file (see below for details on ZIP). Then I unzip them (see below for details on the tool used), and the files are restored. The date of the file is restored, as in standard in the ZIP/UNZIP tools used. When querying using DIR, or in Windows Explorer, the files involved have the same date as they had, before being handled by the ZIP/UNZIP process.
So, all OK.
But then, I'm using the XCOPY /D command, to further manipulate different copies of those files on the disk ... and, XCOPY says : one file is newer than the other one. Given the fact the date, hour, up until minutes is the same .. the difference would be regarding a smaller entity, like seconds ?
All involved disks have NTFS file system.
Example:
C:\my>dir C:\windows\Background_mycomputer.cmd C:\my\directory\Background_mycomputer.cmd
Volume in drive C is mycomputerC
Volume Serial Number is 1234-5678
Directory of C:\windows
31/12/2014 19:50 51 Background_mycomputer.cmd
1 File(s) 51 bytes
Directory of C:\my\directory
31/12/2014 19:50 51 Background_mycomputer.cmd
1 File(s) 51 bytes
0 Dir(s) 33.655.316.480 bytes free
C:\my>xcopy C:\windows\Background_mycomputer.cmd C:\my\directory\Background_mycomputer.cmd /D
Overwrite C:\my\directory\Background_mycomputer.cmd (Yes/No/All)? y
C:\windows\Background_mycomputer.cmd
1 File(s) copied
C:\my>xcopy C:\my\directory\Background_mycomputer.cmd C:\windows\Background_mycomputer.cmd /D
0 File(s) copied
C:\my>xcopy C:\windows\Background_mycomputer.cmd C:\my\directory\Background_mycomputer.cmd /D
0 File(s) copied
C:\my>unzip -v
UnZip 6.00 of 20 April 2009, by Info-ZIP. Maintained by C. Spieler. Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.
Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip/ ;
see ftp://ftp.info-zip.org/pub/infozip/UnZip.html for other sites.
Compiled with Microsoft C 13.10 (Visual C++ 7.1) for
Windows 9x / Windows NT/2K/XP/2K3 (32-bit) on Apr 20 2009.
UnZip special compilation options:
ASM_CRC
COPYRIGHT_CLEAN (PKZIP 0.9x unreducing method not supported)
NTSD_EAS
SET_DIR_ATTRIB
TIMESTAMP
UNIXBACKUP
USE_EF_UT_TIME
USE_UNSHRINK (PKZIP/Zip 1.x unshrinking method supported)
USE_DEFLATE64 (PKZIP 4.x Deflate64(tm) supported)
UNICODE_SUPPORT [wide-chars] (handle UTF-8 paths)
MBCS-support (multibyte character support, MB_CUR_MAX = 1)
LARGE_FILE_SUPPORT (large files over 2 GiB supported)
ZIP64_SUPPORT (archives using Zip64 for large files supported)
USE_BZIP2 (PKZIP 4.6+, using bzip2 lib version 1.0.5, 10-Dec-2007)
VMS_TEXT_CONV
[decryption, version 2.11 of 05 Jan 2007]
UnZip and ZipInfo environment options:
UNZIP: [none]
UNZIPOPT: [none]
ZIPINFO: [none]
ZIPINFOOPT: [none]
C:\my>ver
Microsoft Windows [Version 6.1.7601]
C:\my>zip -?
Copyright (c) 1990-2006 Info-ZIP - Type 'zip "-L"' for software license.
Zip 2.32 (June 19th 2006). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
The default action is to add or replace zipfile entries from list, which
can include the special name - to compress standard input.
If zipfile and list are omitted, zip compresses stdin to stdout.
-f freshen: only changed files -u update: only changed or new files
-d delete entries in zipfile -m move into zipfile (delete files)
-r recurse into directories -j junk (don't record) directory names
-0 store only -l convert LF to CR LF (-ll CR LF to LF)
-1 compress faster -9 compress better
-q quiet operation -v verbose operation/print version info
-c add one-line comments -z add zipfile comment
-# read names from stdin -o make zipfile as old as latest entry
-x exclude the following names -i include only the following names
-F fix zipfile (-FF try harder) -D do not add directory entries
-A adjust self-extracting exe -J junk zipfile prefix (unzipsfx)
-T test zipfile integrity -X eXclude eXtra file attributes
-! use privileges (if granted) to obtain all aspects of WinNT security
-R PKZIP recursion (see manual)
-$ include volume label -S include system and hidden files
-e encrypt -n don't compress these suffixes
C:\my>
Question: I do not want XCOPY to make updates where I know they are invalid cause the time format is doing something wrong. How do I prevent that ?
From how I see, there's different things involved, being XCOPY, very specific ZIP and UNZIP, and NTFS file system. Which one is doing something wrong ?
I must stress that apart from ZIP and UNZIP, there are no other changes done to the file, like changing 1 file, then making a change to another one, in less than 60 seconds time.
At moment of test, the time shown was NOT the current time, and not close to it either. No file is adjusting to the current time, the times refer to last changes of the file in question, which may be any time in the past. In this case, it's one day later, but it can be anything.
I noticed the peculiar behavior Raymond Chen describes when writing a Powershell script (GitHub link) to freshen a zip archive using the System.IO.Compression and System.IO.Compression.FileSystem libraries.
Interestingly, Zip archives can store multiple copies of the same file with identical metadata (name, relative path, modification dates). Extracting the second copy of the file will fail in Windows Explorer because the file already exists.
When trying to prevent re-zipping a file was already archived, I checked the relative path and date, and noticed that there was a discrepancy of up to two seconds in the LastWriteTime. This workaround compensates for the loss of precision:
$AlreadyArchivedFile = ($WriteArchive.Entries | Where-Object {#zip will store multiple copies of the exact same file - prevent this by checking if already archived.
(($_.FullName -eq $RelativePath) -and ($_.Length -eq $File.Length) ) -and
([math]::Abs(($_.LastWriteTime.UtcDateTime - $File.LastWriteTimeUtc).Seconds) -le 2) #ZipFileExtensions timestamps are only precise within 2 seconds.
})
Also, the IsDaylightSavingTime flag is not stored in the Zip archive. As a result I was surprised when extracted files became an hour newer than the original archived file. I tried this several times and saw the extracted file's timestamp incremented by an hour every time it was compressed and extracted.
Here's a very ugly workaround that decreases the archived file time by one hour to make the original source file and extracted file timestamps consistent:
If($File.LastWriteTime.IsDaylightSavingTime() -and $ArchivedFile){#HACK: fix for buggy date - adds an hour inside archive when the zipped file was created during PDT (files created during PST are not affected).
$entry = $WriteArchive.GetEntry($RelativePath)
$entry.LastWriteTime = ($File.LastWriteTime.ToLocalTime() - (New-TimeSpan -Hours 1))
}
There's probably a better way to handle this. Unfortunately I'm not aware of any way to store a Daylight Savings indicator for a file in a .Zip archive, and that information is lost.
How can I read name of source file and send it as archive name in 7zip using cmd archive option.
Now I use:
7z a -t7z V:\archive.7z V:\Backup\*.bak
I want to check bak namefile in V:\Backup (there is always only 1 file) and send it as archive.7z - for example if in V:\Backup is 1 file named "20131028_1100.bak" I want to name archive "20131028_1100.7z"
I found this to work:
Get-ChildItem *txt | ForEach-Object {.\7zr.exe a -t7z $($_.Name).replace('.txt','.7z') $_.FullName}
Example:
PS C:\tools> ls
Directory: C:\tools
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2022/08/01 11:00 578048 7zr.exe
-a---- 2022/08/01 11:02 7 hello.txt
PS C:\tools> Get-ChildItem *txt | ForEach-Object {.\7zr.exe a -t7z $($_.Name).replace('.txt','.7z') $_.FullName}
7-Zip (r) 22.01 (x86) : Igor Pavlov : Public domain : 2022-07-15
Scanning the drive:
1 file, 7 bytes (1 KiB)
Creating archive: hello.7z
Add new data to archive: 1 file, 7 bytes (1 KiB)
Files read from disk: 1
Archive size: 133 bytes (1 KiB)
Everything is Ok
PS C:\tools> ls
Directory: C:\tools
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2022/08/01 11:00 578048 7zr.exe
-a---- 2022/08/01 11:20 133 hello.7z
-a---- 2022/08/01 11:02 7 hello.txt
PS C:\tools> ls
you need a .bat script that execute a FOR command like this:
for %%X in (*) do "7zip\App\7-Zip\7z.exe" a "%%~nX.zip" "%%X"
%%X will catch the file name of every file contained in the folder where you will execute the script (in this case V:\Backup\ and only 1 file would be processed), so %%~nX.zip will take that file name
7zip keep source file name to archive
As "capa" said, it is necessary to use shell commands, because 7zip does not provide a command for this case.
The following edited command is available in order to operate with *.bak files and it is working for "7z" compression extension. It is more efficient than "zip" format in compression rate.
7z Format
FOR %%I IN (.bak) DO "c:\Program Files\7-Zip\7z.exe" a -t7z %%~nI.7z %%~nI.
zip Format
FOR %%I IN (.bak) DO "c:\Program Files\7-Zip\7z.exe" a -tZip %%~nI.zip %%~nI.
In the above commands the " * " symbol before .bak is not appeared. Please add it!
Also add the " * " to the end of each command.
*Create a "bat" file for example "compressbak.bat" on *.bak files directory, copy and paste the preferred command(7z or zip), "Save" the content on "compressbak.bat"! This will create named archives of *.bak files in the same folder that *.bak files saved. Also if you running on Windows x64 and you have a x86 version of 7-Zip you have to follow the right path in order to call the 7z.exe file. "c:\Program Files (x86)\7-Zip\7z.exe"
Folder and bat file content!
I hope that it helps you!!!