Computer Hope

Microsoft => Microsoft DOS => Topic started by: mioo_sara on May 29, 2009, 03:55:36 AM

Title: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on May 29, 2009, 03:55:36 AM
how  can  we be sure that  (.rar .zip ) files are unziped  successfully  and delet them?
i  need some scripts  in  batch file format  that check  to  see if extraction  is complete successfully   then  delet (.zip .rar) files
is there any  way  to  help?
by  the way
1- i have winrar installed  in  my  system
2-  broken (.zip .rar) files should be ignored of deletion
thanks
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: Reno on May 29, 2009, 04:28:15 AM
i think i've this kind of script that i use in the past:

here it is:
_unrar.bat
Code: [Select]
@echo off

for /f "tokens=*" %%a in ('dir /b *.rar *.zip') do (
%%~xa e -y "%%~a" && attrib +h "%%~a"
)

pause

and _clean.bat
Code: [Select]
@echo off

for /f "tokens=*" %%a in ('dir/b/ah *.zip *.rar') do (
for /f "tokens=*" %%b in ('%%~xa lb "%%a"') do (
dir/b "%%b" >nul 2>&1 && (del/a "%%a" && echo DELETE: %%a)
)
)

i use the rar.exe and 7zip.exe (the command line version). copy both files to the same folder as the .bat files, and rename it to '.rar.exe' and '.zip.exe'

how _unrar works:
1. it extract the files, prompt for password if any, on successful, it hide the file (treating the hidden file(s) as recycle bin)

how _clean works: (cleaning the "recycle bin")
it check for hidden rar zip files, then list the content, and check if the content is already extracted, once it sure, it then delete the rar zip file for good.
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on May 29, 2009, 07:05:04 AM
dear reno i tried your scripts but i have error message

Quote
'.rar' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue . . .


i  even  found ( rar.exe and 7z.exe ) and copied them  in folder next to  my.bat file but it can't extract or even  find my  (.zip .rar ) files !!
rar.exe path  that i  found =C:\Program Files\WinRAR\Rar.exe
7z.exe= i download it

but  i  tried another script that can  perfectly  extract  my  (.zip  and .rar ) files

Quote
@echo OFF
for %%f in (*.zip *.rar) do "C:\Program Files\WinRAR\Winrar.exe" x "%%f"
it does not need me to  copy  anything ..but there is a problem  that i mentioned before in  my  post number 1

how can  i  be sure that (.zip and .rar ) files have been  extracted 100% successfully?  and then  delet (.zip and .rar ) files?
and how to  ignore broken  files and those files that has not been  extracted successfully from  deletion?

thanks
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: devcom on May 29, 2009, 07:30:51 AM
you need to use for loop and findstr to filter output

Code: [Select]
C:\CMD>rar x GETIP |findstr "Wypakowuję"

Wypakowuję  GETIP.exe                                                 OK


Code: [Select]
        1             2                                                         3
Wypakowuję  GETIP.exe                                                 OK

then you need to match 3 token
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on May 29, 2009, 08:59:55 AM
devcom
what are those codes?
 should i type them  in  CMD?
i  need batch  codes
can  you  help with  that?
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: Reno on May 29, 2009, 09:48:45 AM
i  even  found ( rar.exe and 7z.exe ) and copied them  in folder next to  my.bat file but it can't extract or even  find my  (.zip .rar ) files !!
rar.exe path  that i  found =C:\Program Files\WinRAR\Rar.exe
7z.exe= i download it

Answer:
i use the rar.exe and 7zip.exe (the command line version). copy both files to the same folder as the .bat files, and rename it to '.rar.exe' and '.zip.exe'
you miss this important step, rename rar.exe to '.rar.exe' and '7z.exe' to '.zip.exe', are you sure 7z.exe is the command-line version?
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on May 29, 2009, 10:15:38 AM
Quote
you miss this important step, rename rar.exe to '.rar.exe' and '7z.exe' to '.zip.exe',
dear reno
i did not missed it ! i  just did not report it back 
first  in  windows xp  unfortunately we can't add (.) to  first part of files names i tried to  rename rar.exe to .rar.exe  but i  have a error report that windows is  unable to  rename it to  .rar.exe i even  tried to  rename it  to '.rar.exe' but you  can  guess what happened
Quote
are you sure 7z.exe is the command-line version?

well  i  am  sure  but what  about  (*.rar ) files?
why it can't even  extract them? i  copied rar.exe and myfile.rar and my.bat ito  a folder and start my.bat but  i  have still  that error message
what should  i  do?
what  about  that scripts  that  i  mentioned ?  that is working  perfectly
cant  you  fix that or find another way?
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: Reno on May 29, 2009, 10:28:23 AM
it working fine here, except i am doing it in command line
ren rar.exe .rar.exe

as for the modification the script you mentioned:
@echo OFF
for %%f in (*.rar) do "C:\Program Files\WinRAR\rar.exe" e "%%f" && del "%%f"

the same to do wit the zip file
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: TheHoFL on May 29, 2009, 10:41:28 AM
Are you looking to have the RAR extract and then immediately delete or to have a directory scanned and delete the RAR files that have been extracted?
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on May 29, 2009, 02:28:01 PM
well  first of all  thanks for helping me reno
i  think  with  your help  at last  i reached somewhere
========================================

i  tried to  replace your script with  below script
Quote
@echo OFF
for %%f in (*.zip *.rar) do "C:\Program Files\WinRAR\Winrar.exe" x "%%f" && del "%%f"

it can  now extract any ( zip  or rar) files and then  delet the source files and if found broken  or password protected file ignore it from  deletion
but i know that this program  can  now work  just under winxp with  winrar istalled
i  have  some question=
1-  how is it possible to  rename rar.exe to .rar.exe ? windows xp  does not allow  to  put (.) at the  first character of files
is it some kind of trick  that i am  not aware of?
2-  what is that  (.) doing?  is it that  important?
3-  you  put (e) in  your script (rar.exe" e ")  but i replace it to  x(means any  file) what is that (e) ?
by  the way  i am  using windows xp sp2 and i have winrar 3.80  installed on  my  system
i  found rar.exe in  winrar folder with 315 kb size and 7zip(renamed to zip.exe) with 144 kb
are the size different from  yours?
is it possible to  upload both  your files?
thanks
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on May 29, 2009, 02:29:05 PM
dear TheHoFL
i  want to  extrat  zip  and rar files and then  delet  zip  and rar files that have been  completely  extracted and keep  the others that are broken  or password protected
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: Reno on May 31, 2009, 10:50:59 PM
1-  how is it possible to  rename rar.exe to .rar.exe ? windows xp  does not allow  to  put (.) at the  first character of files
is it some kind of trick  that i am  not aware of?
2-  what is that  (.) doing?  is it that  important?
3-  you  put (e) in  your script (rar.exe" e ")  but i replace it to  x(means any  file) what is that (e) ?

1. i already told you how to do it, see above, ren rar.exe .rar.exe
2. it just to make the batch shorter, the code parse the extension which is .rar and .zip, that's why i rename the exe to .rar.exe and .zip.exe
3. type rar.exe /? to find out
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on June 01, 2009, 06:32:02 AM
at last i did it reno !! thanks man 
with  your help  i  renamed those files ..but you  should have told me to  do  this through  a .bat file !! i  was renaming  rar.exe and 7zip.exe with  windows xp !! but i  tried this command in  a batch  file
ren rar.exe .rar.exe
ren 7zip.exe .zip.exe
and its done !!!
but now there is still  one problem
it always remains one file (zip file) undeleted after extraction why?
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: Reno on June 01, 2009, 08:31:57 AM
it always remains one file (zip file) undeleted after extraction why?

what is your code? in what condition the zip file is not deleted?
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on June 02, 2009, 10:26:15 AM
sorry for late
Quote
what is your code? in what condition the zip file is not deleted?

well  i used your(reno) scripts in  post #2
i create 3 new folders and compressed them  to  following names
New Folder.rar
New Folder (2).zip
New Folder (3).rar

then  copied ( .rar.exe .zip.exe and reno.bat ( your batch  program file) )

now i execute it
it extract  one folder just New Folder (2).zip and never any of others
why? whats wrong? it can  extract zip  file  so  it could not be because of my  .zip.exe , right?
as i mentioned before i have winrar 3.80  installed and my  (.rar.exe .zip.exe) size is below
.rar.exe === 315kb
.zip.exe === 146kb
i found rar.exe in  winrar folder

thanks

Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: Reno on June 03, 2009, 01:30:15 AM
type '.zip.exe' at command prompt:
it should display something as follow:
Code: [Select]
D:\batch>.zip

7-Zip 4.57  Copyright (c) 1999-2007 Igor Pavlov  2007-12-06

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
       [<@listfiles...>]
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on June 03, 2009, 06:10:37 AM
hi  dear reno
well  i  don't have 7zip  installed on  my  system  so  when  i typed .zip.exe in  CMD i  saw  error massage


Quote
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\sss>.zip.exe
'.zip.exe' is not recognized as an internal or external command,
operable program or batch file.

well  i did not navigate to my  folder through  CMD  ;D ;D
but  i did something else that defined my   file is not bad !!
i   copied .zip.exe in  a folder  and  typed .zip.exe in  a bat file and executed bat file
you  can  see the result

Quote
F:\bbb\delet zip>.zip.exe

7-Zip 4.62  Copyright (c) 1999-2008 Igor Pavlov  2008-12-02

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
       [<@listfiles...>]

<Commands>
  a: Add files to archive
  b: Benchmark
  d: Delete files from archive
  e: Extract files from archive (without using directory names)
  l: List contents of archive
  t: Test integrity of archive
  u: Update files to archive
  x: eXtract files with full paths
<Switches>
  -ai[r[-|0]]{@listfile|!wildcard}: Include archives
  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
  -bd: Disable percentage indicator
  -i[r[-|0]]{@listfile|!wildcard}: Include filenames
  -m{Parameters}: set compression Method
  -o{Directory}: set Output directory
  -p{Password}: set Password
  -r[-|0]: Recurse subdirectories
  -scs{UTF-8 | WIN | DOS}: set charset for list files
  -sfx[{name}]: Create SFX archive
  -si[{name}]: read data from stdin
  -slt: show technical information for l (List) command
  -so: write data to stdout
  -ssc[-]: set sensitive case mode
  -ssw: compress shared files
  -t{Type}: Set type of archive
  -v{Size}[b|k|m|g]: Create volumes
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options
  -w[{path}]: assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames
  -y: assume Yes on all queries

so  my  file is a command version  right RENO?
now what's wrong?  would you  please read my  previous post again?
thanks
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: Reno on June 03, 2009, 07:17:32 AM
admitted it that i dont have an answer for this.
i have used that batch script for months, and works well as i intend it to.

change echo off to echo on, then if you could post some screen output which line and file name goes wrong, i try my best to assist.
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on June 03, 2009, 09:30:24 AM
hi  to  all  specially  my  dear RENO
RENO you  were right !!  i had created 2 empty  folders and  compressed them..... because of that  program  could not extract anything
i apologize for that i  did not saw that there are some switches in  your program
======================================================
but now  i created 2 folders and put some files inside both  of them  and then  compressed them  to  names below
my rar.rar
my zip.zip
and added (.zip.exe , .Rar.exe and reno.bat) and execute bat file it extracted all  files and folders and deleted my rar.rar file but my zip.zip is still  exist !! it's just hiden but not deleted
below you  can  see the  result in a CMD window
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on June 03, 2009, 09:31:01 AM
Quote
C:\delet zip>for /F "tokens=*" %a in ('dir /b *.rar *.zip') do (%~xa e -y "%~a"
  && attrib +h "%~a" )

C:\delet zip>(.rar e -y "my rar.rar"   && attrib +h "my rar.rar" )

RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help


Extracting from my rar.rar

Extracting  New Rich Text Document.rtf                                OK
All OK

C:\delet zip>(.zip e -y "my zip.zip"   && attrib +h "my zip.zip" )

7-Zip 4.62  Copyright (c) 1999-2008 Igor Pavlov  2008-12-02

Processing archive: my zip.zip

Extracting  my zip
Extracting  my zip\New Text Document.txt

Everything is Ok

Folders: 1
Files: 1
Size:       10
Compressed: 251

C:\delet zip>for /F "tokens=*" %a in ('dir/b/ah *.zip *.rar') do (for /F "tokens
=*" %b in ('%~xa lb "%a"') do (dir/b "%b"   1>nul 2>&1  && (del/a "%a"   && echo
 DELETE: %a ) ) )

C:\delet zip>(for /F "tokens=*" %b in ('.zip lb "my zip.zip"') do (dir/b "%b"
1>nul 2>&1  && (del/a "my zip.zip"   && echo DELETE: my zip.zip ) ) )

C:\delet zip>(dir/b "7-Zip 4.62  Copyright (c) 1999-2008 Igor Pavlov  2008-12-02
"   1>nul 2>&1  && (del/a "my zip.zip"   && echo DELETE: my zip.zip ) )

C:\delet zip>(dir/b "Error:"   1>nul 2>&1  && (del/a "my zip.zip"   && echo DELE
TE: my zip.zip ) )

C:\delet zip>(dir/b "Incorrect command line"   1>nul 2>&1  && (del/a "my zip.zip
"   && echo DELETE: my zip.zip ) )

C:\delet zip>(for /F "tokens=*" %b in ('.rar lb "my rar.rar"') do (dir/b "%b"
1>nul 2>&1  && (del/a "my rar.rar"   && echo DELETE: my rar.rar ) ) )

C:\delet zip>(dir/b "New Rich Text Document.rtf"   1>nul 2>&1  && (del/a "my rar
.rar"   && echo DELETE: my rar.rar ) )
DELETE: my rar.rar

C:\delet zip>(dir/b "my rar"   1>nul 2>&1  && (del/a "my rar.rar"   && echo DELE
TE: my rar.rar ) )

C:\delet zip>pause
Press any key to continue . . .
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: Reno on June 03, 2009, 09:47:11 AM
i am speechless.
the 2 batch file is not meant to be combined into one.

instead use this:
Code: [Select]
@echo off

for /f "tokens=*" %%a in ('dir /b *.rar *.zip') do (
%%~xa e -y "%%~a" && del "%%~a"
)
pause

there is a HUGE bug that need to be fix in _clean.bat at post #2, there is no 'lb' switch in 7z.exe. so don't use script at post#2. thank you for reporting a bug. ;)
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on June 03, 2009, 02:53:34 PM
wow thanks RENO ;)
what a powerful  script it's so  fast even  before i  start  it  it  finished !! :o  fantastic it's working like a charm it extract files and delet compressed files with  no error .  it is very  delightful  that this website has a programmer like you
==============================================
now with  a test i have my  2 final  questions   that will  be very  greatful  if you  solve  them

how can  we replace (*.rar .*.zip) with our file names? i  don't want to  all  files to be extracted .just need those files that i order get extracted
thanks can  you  give an  example for replacable file names (for both  zip and rar files at the same time)
thanks ;)
Title: Re: delet (.rar .zip ) files after successfully unzip
Post by: mioo_sara on June 05, 2009, 06:25:35 AM
has someone seen RENO around? :'(