Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

No! ...Don't Unzip there!!


  • Please log in to reply
2 replies to this topic
Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
....but perhaps u did... now what?

If u've faced a situation where u've unzipped a zip file to a wrong folder which had a zillion files originally and now all the files r mixed, then u'd know the pain to do this:
1. look in zip file
2. go to folder & delete the file u just looked up
3. repeat untill all files r done!

here's some help... this script will ask for the target folder and then the compressed file and clear the files from the target folder that are also there in the compressed file.

Reqmts : WinRAR (change path in script)
though u can change the script to adapt it to any utility supporting cmd-line extraction, i've chosen winrar coz of its support for many archive types, its fast and i like it!

Edit: changed script... i think this is a better method... and yeah it now also displays a list of files removed.

;___________________________________________
;______De-Unzip Script______________________

;This will remove files which are accidently
;extracted to a folder from a compressed file.

;___________________________________________


;Enter path to WinRAR here:
WRARPath = E:\Program Files\WinRAR\WinRAR.exe

;___________________________________________


SetBatchLines, 10ms


;Caution Message
Coordmode, tooltip, screen
ToolTip, ATTENTION!  Please BACKUP the target`nfolder before running DeUnZip, 330, 300
sleep, 4000
ToolTip


FileSelectFolder, Folder,,, Select Target Folder
ifnotexist, %Folder%, exitapp

FileSelectFile, Archive, 1,, Select Compressed File
ifnotexist, %Archive%, exitapp


;Remove if already existing temp files
FileRemoveDir, %temp%\DeUnZip, 1
FileDelete, %temp%\DeUnZip.tmp
FileDelete, %temp%\Deleted Files.txt


;extract compressed file again to temp folder
RunWait, %WRARPath% X -o+ "%Archive%" "%temp%\DeUnZip\",,min


;generate file list
Loop,%temp%\DeUnZip\*.*,, 1
{
	FileAppend, %A_LoopFileFullPath%`n, %temp%\DeUnZip.tmp
}


;Delete files & generate report
Loop, Read, %temp%\DeUnZip.tmp, %temp%\Deleted Files.txt
{
	StringReplace, NewPath, A_LoopReadLine, %temp%\DeUnZip, %Folder%, A
	
	IfExist, %NewPath%
	{
		FileAppend, %NewPath%`n
		FileSetAttrib, -R-H-S, %NewPath%
		FileDelete, %NewPath%
	}
}



;The next loop removes empty folders
RemFldr:
Loop, e:\stuff\cracking\*.*, 2, 1
{
	ifinstring, A_LoopFileFullPath, .zip, continue
	Current = %A_LoopFileFullPath%
	total = 0
	Loop, %Current%\*.*
	{
		total ++
	}

	ifequal, total, 0
	{
		FileSetAttrib, -H-R-S, %Current%
		FileRemoveDir, %Current%
		IfNotExist, %current%, setenv, Done, Yes
	}
}

ifEqual, Done, Yes
{
	Done = No
	Goto, RemFldr
}


;clear temporaries
Run, %temp%\Deleted Files.txt
FileRemoveDir, %temp%\DeUnZip, 1
FileDelete, %temp%\DeUnZip.tmp
FileDelete, %temp%\Deleted Files.txt

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


fruityth1ng
  • Guests
  • Last active:
  • Joined: --
This might be oversimplifying it, but couldn't you just sort the directory on the "date modified" column, and check out the time there?

Otherwise,
thanks for the script! :)

Micha
  • Members
  • 539 posts
  • Last active: Dec 31 2011 01:43 PM
  • Joined: 15 Nov 2005

This might be oversimplifying it, but couldn't you just sort the directory on the "date modified" column, and check out the time there?


Hi,
most archivers extract the files with the date from the original files, so they can't be found by sorting them.

I'm using a more complex solution (but fine for me):
Extract the ZIP to another clean folder. With i.e. Beyond compare or any other folder compare tool, compare the 2 folders. You can select all identical files and delete them.

Ciao
Micha