1

I'm trying to write a batch which can process files dropped from within a 7zip archive browser window (by dropping the files from the 7-zip window to the batch file in the windows explorer window which will result in the batch being run with the dropped file's path as its first argument).

Dropping files from a windows file explorer window works fine, but when i test this from within a 7zip archive browser window the temporary file which 7zip creates doesn't exist anymore once the batch is run.

Here's the test batch program:

if not exist "%1" echo %1 does not exist

Here's the test setup to make things clearer:

enter image description here

Echo outputs the message

C:\Users\...\AppData\Local\Temp\7zECF421759\test.txt does not exist

Is there a way to pin the temporary file until the end of the batch so that it is not deleted prematurely?

EDIT 1:

Found this text in the 7-zip FAQ:

Why does drag-and-drop archive extraction from 7-Zip to Explorer use temp files?

7-Zip doesn't know folder path of drop target. Only Windows Explorer knows exact drop target. And Windows Explorer needs files (drag source) as decompressed files on disk. So 7-Zip extracts files from archive to temp folder and then 7-Zip notifies Windows Explorer about paths of these temp files. Then Windows Explorer copies these files to drop target folder.

Whether or not it's possible to replicate the behavior within a batch file (or any other program which isn't windows explorer) seems to depend on how 7-zip notifies windows explorer.

1 Answers1

2

Yeah 7Zip Extracts to a temp folder in situations like this and viewing files in archives. You could easily automate this by just extracting the archive and then processing it without needing to open archive, drag content etc. As seen Here You can also extract only specific files from an archive

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS

:: Just Sets 7z variable Set "7zip=C:\Program Files\7-Zip\7z.exe"

:: Extract Whole Archive "%7Zip%" x "Archive.7z" -aoa -o"%temp%\ArcTemp" -r -y

:: Only extract 1.txt from archive "%7Zip%" x "Archive.7z" -aoa -o"%temp%\ArcTemp" "1.txt" -r -y

if exist "%temp%\ArcTemp\1.txt" echo File Exists. pause

7zip x KEEPS directory structure when extracting 7zip e DONT Keep directory structure when extracting -aoa means it will overwrite all files -aos dont overwrite. -o"Dir" is where files will be extracted to. -r Recurses and -y is skip confirmation popups.

Hope it helps :)

Venom
  • 71