Computing.Net > Forums > Programming > a batch code for exclude password protected

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

a batch code for exclude password protected

Reply to Message Icon

Name: niki chan
Date: May 24, 2009 at 07:07:39 Pacific
OS: Windows XP
CPU/Ram: 3.4
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: niki chan
Date: May 24, 2009 at 22:03:15 Pacific
Reply:

it seems that this question is to hard to answer isnt it?


0

Response Number 2
Name: reno
Date: May 25, 2009 at 21:36:53 Pacific
Reply:

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.


0

Response Number 3
Name: hadi boy
Date: May 25, 2009 at 23:03:56 Pacific
Reply:


it seems to be hard


0

Response Number 4
Name: niki chan
Date: May 25, 2009 at 23:13:03 Pacific
Reply:

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?


0

Response Number 5
Name: reno
Date: May 25, 2009 at 23:35:21 Pacific
Reply:

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))
)


0

Related Posts

See More



Response Number 6
Name: niki chan
Date: May 26, 2009 at 03:17:52 Pacific
Reply:

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


0

Response Number 7
Name: reno
Date: May 26, 2009 at 22:25:13 Pacific
Reply:

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

0

Sponsored Link
Ads by Google
Reply to Message Icon

How make search for any f... Prolog Programming Code



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: a batch code for exclude password protected

vbs password protect script help www.computing.net/answers/programming/vbs-password-protect-script-help/13524.html

Date question for a batch www.computing.net/answers/programming/date-question-for-a-batch/16789.html

C++ password www.computing.net/answers/programming/c-password/8775.html