[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

windows batch to delete incomplete downloads (might be a tough one)

Posted on 2011-10-19
22
Medium Priority
?
306 Views
Last Modified: 2012-05-12
Ok, 500 for this script is probably not enough, and I wish I could issue more.   This is going to be a complicated script request.  

I need a batch script that does the following:

Searches all hard drives for a particuler folder name e.g., "qagame"
Searches those folders for duplicate filenames...
and deletes the one with the most numerical digits in it.

The purpose of this is to delete incomplete downloads in these folders which normally tag the file with a bunch of digits at the end.  Example...

Banimod.pk3  <---this is the complete file and should not be deleted
Banimod.34t678c.pk3  <---this is the incomplete download and is trash to be deleted

If there is a better way to do this I am open to suggestions, as long as I can use windows batch script.  
0
Comment
Question by:icecom4
  • 10
  • 7
  • 3
  • +1
22 Comments
 
LVL 6

Expert Comment

by:Gerald26
ID: 36994680
First simple qustion before scripting:
Are all incomplete download in this form  NAME.RANDOM.PK3 ?
If so, run this command and tell me if the output is only the files you want to delete:

dir \*.*.pk3 /s

0
 
LVL 30

Expert Comment

by:flubbster
ID: 36994812
good idea. simply find anything with two delimiters...
0
 

Author Comment

by:icecom4
ID: 36994940
I ran that script.  The output did include all the trash files I want to delete, but it also caught some files with correct names.  This is because some of the files already have version numbers in it.  

output:
Directory of C:\qagame\

04/04/2011  06:17 PM            33,627 DRoemblem.d4f3cbf1.pk3  <-----incomplete download
04/05/2011  11:59 AM         7,678,437 sackmod-1.1.7.65f33a0c.pk3  <-----incomplete download
04/05/2011  11:58 AM            10,828 sackmod-1.1.7.pk3 <-----legit, need to keep
04/12/2011  07:36 PM         7,866,954 sackmod-1.1.9.pk3 <-----legit, need to keep
04/05/2011  12:03 PM         7,649,552 sackmod-20070125-2.1.8.pk3 <-----legit, need to keep
04/04/2011  06:14 PM        12,869,980 sackmod-20070125-2.1.8_DRiv1.pk3 <-----legit, need to keep
               6 File(s)     36,109,378 bytes
Press any key to continue . . .

Ok, notice the third is sackmod 1.1.7, but the one above it is the exact same name with a random numbers taged on the end...this is the incomplete download.  This is what I was talking about regarding finding the duplicate but with that random extra set of numbers and letters (mostly numbers).  I dont know any other way to do it.  
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 30

Expert Comment

by:flubbster
ID: 36995061
Are they always 8 random characters?

if so, try this:

dir \*.????????.pk3
0
 
LVL 6

Expert Comment

by:Gerald26
ID: 36995079
Hi again
Now that's a challenge !
I dont know if i'll be able to make the script now. I need time and I really hope some expert do it before me.

What we can say is that if file "Name.a.b.c.d.pk3" exists and "Name.a.b.c.d.e.pk3" exists then the 2nd one is not legit and must be deleted (or moved in a Delete folder)
Not 'that' hard if we compare file names, consider . as a separator and count arguments. But the loop will definitely not be easy to make.

Ill come back to you as soon as I can with the solution if I get it

Regards

Gerald
0
 
LVL 6

Expert Comment

by:Gerald26
ID: 36995083
good one flubbster, that might do the trick
0
 
LVL 6

Expert Comment

by:Gerald26
ID: 36995135
Hopes gones :(


C:\temp\2>dir
19/10/2011  20:41                24 d.d.d.d.d.d.d.d.pk3
19/10/2011  20:42                24 d.d.d.oolkdl.pk3
19/10/2011  20:41                24 d.pk3
 
C:\temp\2>dir *.??????.pk3

19/10/2011  20:41                24 d.d.d.d.d.d.d.d.pk3
19/10/2011  20:42                24 d.d.d.oolkdl.pk3

0
 

Author Comment

by:icecom4
ID: 36995149
yes, they are all 8 random digits.  

that batch you gave me returned output "File not found" though
0
 
LVL 30

Accepted Solution

by:
flubbster earned 1400 total points
ID: 36995160
syntax was hosed...

dir *.????????.pk3
0
 

Author Comment

by:icecom4
ID: 36995164
I was responding to flubbster just now, FYI
0
 

Author Comment

by:icecom4
ID: 36995173
yep flubb that batch worked, and yes it listed the incomplete trash files only :)
0
 

Author Comment

by:icecom4
ID: 36995194
i need to do somrthing for work but I will check back in a couple hours, thanks for your help
0
 
LVL 6

Expert Comment

by:Gerald26
ID: 36995239
still dont know why it wouldnt work on a french seven uiltimate 64 admin cmd. console :
Technically it's correct.

C:\temp\2>dir *.????????.pk3

 Le volume dans le lecteur C n'a pas de nom.
 Le numéro de série du volume est 4485-1904

 Répertoire de C:\temp\2

19/10/2011  20:53                24 sackmod-1.1.7.65f33a0c.pk3
19/10/2011  20:54                24 sackmod-1.1.7.pk3
19/10/2011  20:54                24 sackmod-1.1.9.pk3
19/10/2011  20:54                24 sackmod-20070125-2.1.8.pk3
19/10/2011  20:54                24 sackmod-20070125-2.1.8_DRiv1.pk3
               5 fichier(s)              120 octets
               0 Rép(s)  389 272 547 328 octets libres
0
 
LVL 39

Expert Comment

by:BillDL
ID: 36995422
OK, my first instinct is not to try some hit and miss parsing of file names that tries guess which is incomplete based on random digits.  It's too risky to run as entirely automated, judging by the inconsistency of file naming conventions.

Instead, or as an additional check on file names that would appear to match, why not TEST each of the *.PK3 files.

A "pack" file is just a *.ZIP file by another extension, isn't it?  So if it's incomplete then it can theoretically be tested for integrity using any "unzipping" utility that supports the "test" or "simulate unzipping command line switches, and it should fail.

How large are these *.PK3 files?

What happens if you rename one, changing the .PK3 extension to .ZIP and then try to unzip it to its own folder with WinZip, 7-Zip,WinRAR, or even the native Windows unzipping function?

The giveaway of a "zipped" file is usually the existence of "PK" as the very first characters in the file header when viewed in a text editor like Windows notepad.  Additionally, right at or near the end of the contents (in a text editor) you usually have a list of files in the archive immediately suffixed by "PK".

From reading up on the *.PK3 file extension, however, I see that (in one example) Quake Live used some wacky method of encoding its files so that standard unzippers won't unpack it.  Despite this there seem to be some enterprising people who have written programs that can.

Simple Test with 7-Zip:

"C:\Path_To\7z.exe" t "C:\Path_To\FileName.zip"

should return an %errorlevel% as Zero and something like this IF the archive is complete:

Everything is OK
Size:   xxxxxxx
Compressed: xxxxxxx

If not a valid Zip file, it should return some other %errorlevel% (such as 2) and display:

Error: Can not open file as archive

So the results are "parseable", even if the program output is redirected to NUL.

Have a look at your *.PK3 files and tell us what you come up with.
0
 
LVL 39

Expert Comment

by:BillDL
ID: 36995543
I will be out to work soon, so I will leave you with some code to either run on its own or for one of the other experts to integrate into another batch file that thins out the results to fewer file names.

Be aware that I HAVE NOT tested this.  It has an "echo del" in it, so it won't actually delete anything until that echo is removed.  It will display what WOULD be deleted and let you check if it worked.

DAMN!!  The "add file" function here is screwed and the copy and paste isn't working either.
0
 

Author Comment

by:icecom4
ID: 36995553
doing dir *.????????.pk3  comes up with only the incomplete files.  I tested it on serveral folders which have these incomplete files.  So I think it is an acceptable risk.  Absolutly none of the stock program files or important .pk3 files have those random ".????????.pk3" at the end.

I think the direction I want to go is having a script which deletes files based on this.  While I dont have time to test right now, would this work.?

@echo off                                            
set folder=
for %%D in (C D E F G H I J K L M N O P Q R S T U V W X Y) do (
  for /F "tokens=*" %%P in ('dir /a:d /s/b %%D:\*etmain ^| findstr /L /E /i "\etmain"') do (
      del /s /q "%%~P\*.????????.pk3"
  )
)
0
 
LVL 6

Assisted Solution

by:Gerald26
Gerald26 earned 600 total points
ID: 36995704
Still doesnt work on my PC ^^ but the script itself is good to me.

I'd add an error control and modify this part

for /F "tokens=*" %%P in ('if exist %%D: dir /a:d /s/b %%D:\*etmain ..........

0
 

Author Comment

by:icecom4
ID: 36996039
Gerald26, are you using win xp or 7?  I notice windows 7 does some odd things with most of my batch scripts.  
0
 
LVL 6

Expert Comment

by:Gerald26
ID: 36996056
French seven ultimate 64bit 6.1.7601 sp1
Got no problem scripting batchs... it's jsut this one *.????????.pk3 that doesn't work, but ill eventually find out why :)
0
 

Author Comment

by:icecom4
ID: 36996693
I just ran the script on windows XP and it works like a charm.  I ran it under windows 7, and it seems like it is searching but it does not delete anything.  I tried a few similar delete scripts which I know work on xp, and I just found that they do not work on windows 7.  I have no idea why.  

set folder=
for %%D in (C D E F G H I J K L M N O P Q R S T U V W X Y) do (
  for /F "tokens=*" %%P in ('dir /a:d /s/b %%D:\*qagame ^| findstr /L /E /i "\qagame"') do (
      del /s /q "%%~P\*.????????.pk3"
  )
)
0
 

Author Comment

by:icecom4
ID: 36996712
ugh...disregard, i forgot the notorious "run as administrator" for every task in win7.  
0
 

Author Closing Comment

by:icecom4
ID: 36996739
Thanks guys, I used the script I posted above, used *.????????.pk3 to find the files I wanted, and also included error correction posted by Gerald.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question