Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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 errorlevelmethod 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.

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?

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

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 movedthanks for your help

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

![]() |
How make search for any f...
|
Prolog Programming Code
|

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