a batch code for exclude password protected

May 24, 2009 at 07:07:39
Specs: Windows XP, 3.4
a batch code for exclude password protected files from move
hi and thanks for your great site i love it
i have a folder named "source" its a subfolder. there is lots of (.exe .zip .rar )files in this folder
some of these files are compressed and are password protected
now i want to move any files from "source" folder and just (.exe .zip .rar )files to my current folder
ok i can do it easily but i need those files that are password protected to be exclude from being moved
the other files should be moved
how can i exclude them?
is there a way?
can you give me a batch code?
thanks

See More: a batch code for exclude password protected

Report •


#1
May 24, 2009 at 22:03:15
it seems that this question is to hard to answer isnt it?

Report •

#2
May 25, 2009 at 21:36:53
method 1:
use the appropriate command-line compression tools, eg. rar.exe to check if rar files is password-protected, not sure if rar.exe support zip files also.
then check out the errorlevel

method 2:
research on the binary format of compressed rar,zip files. check out the header and find out which byte indicate it's password protected. i've no time to google on this.

method 3:
use another language that has zip,rar compression library. google also on this. i think perl has it.


Report •

#3
May 25, 2009 at 23:03:56

it seems to be hard

Report •

Related Solutions

#4
May 25, 2009 at 23:13:03
use the appropriate command-line compression tools, eg. rar.exe to check if rar files is password-protected

dear reno can you give me an example?


Report •

#5
May 25, 2009 at 23:35:21
example with winrar, since i've winrar installed. so using command-line rar.exe instead of GUI winrar.exe

testing

D:\batch>rar lb -p- nopassword.rar
yahoonoscript.txt

D:\batch>echo %errorlevel%
0

D:\batch>rar lb -p- passworded.rar

Encrypted file:  CRC failed in passworded.rar (password incorrect ?)

D:\batch>echo %errorlevel%
3

from the above testing, we now know rar.exe return errorlevel 3 if the file is password protected. so the batch code would be something like this:

@echo off & setlocal enabledelayedexpansion

for %%a in (*.rar) do (
	rar lb -p- "%%a" >nul 2>&1
	if !errorlevel!==0 (echo %%a 	- has no password) else (
	if !errorlevel!==3 (echo %%a 	- password protected) else (
			    echo %%a 	- unknown error))
)


Report •

#6
May 26, 2009 at 03:17:52
hi dear reno
i should confess that i am surprised with your knowledge
thanks for helping me.and i should say that i have winrar in my drive C: installed myself
so i tried below script from your last post

@echo off & setlocal enabledelayedexpansion

for %%a in (*.rar) do (
rar lb -p- "%%a" >nul 2>&1
if !errorlevel!==0 (echo %%a - has no password) else (
if !errorlevel!==3 (echo %%a - password protected) else (
echo %%a - unknown error))
)

i copied 2 .rar file in a folder 1 password protected and the other no password protectd and tried this script.. but i have - unknown error message for both files ! should i copy all the recent post?
and as i mentioned i have a subfolder named "source"contained files i want not only detect password protected files and ignore them from being moved but also move the rest files that are not password protected can you write complete script?
files are different (rar zip and exe ) if winrar can't detect all of them at once ok at least (.rar) file would be enough
in this case half of them has being moved

thanks for your help


Report •

#7
May 26, 2009 at 22:25:13
i learn scripting from some of the great gurus in this forum some time ago, and still need learning.

as for returning error other than 0 and 3, you need to do debugging in your computer.
from cmd prompt type:

D:\batch>rar lb -p- passworded.rar

Encrypted file:  CRC failed in passworded.rar (password incorrect ?)

D:\batch>echo %errorlevel%
3

take a few sample from the rar files, and check for the errorlevel of both passsworded and non password rar files. see if the result of errorlevel is consistent from the sampling. and take notice on the errormessage of rar.exe

Report •


Ask Question