Batch to search all drives for specified file

Microsoft Windows xp professional w/serv...
February 27, 2010 at 00:57:11
Specs: Windows XP, 1GB
Hello, I want to create a batch file that scans all my drives for "basecontent.7z" and extract all content of archive to directory where the batch file has been executed from. Here is what I have so far and it isn't refined. Now It works only if the archive is placed anywhere within the same drive as batch file.

for /f "delims=" %%a in ('dir /s /b \^|findstr.exe /i /c:"\basecontent.7z"') do 7za.exe x "%%a"&&goto a
:a


See More: Batch to search all drives for specified file

Report •

#1
February 27, 2010 at 02:01:05
If you know which drive letters you have, try this. If the bat needs to
figure it out, it will take more doing.
----------------------------------------

@echo off & setLocal EnableDELAYedeXpansion

for %%d in (c d e f) do (

for /f "tokens=* delims= " %%a in ('dir/b/s %%d:\basecontent.7z') do (
7za.exe x "%%a"
)
)


=====================================
Helping others achieve escape felicity

M2


Report •

#2
February 27, 2010 at 02:25:41
Yeah this works, but it would be better to make bat to
figure it out, 'cause on other computer drives may not be named as usual ( C; D...). Would that be possible?

Report •

#3
February 27, 2010 at 03:43:54
@echo off & setLocal EnableDELAYedeXpansion

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 z) do (
  if exist %%d: (
      for /f "tokens=* delims= " %%a in ('dir/b/s %%d:\basecontent.7z 2^>nul') do (
        7za.exe x "%%a"
      )
  )
)


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
February 27, 2010 at 03:52:59
That did the trick. Thanks a lot! :))

Report •

#5
February 27, 2010 at 04:13:01
Be careful that when trying to access certain (unused) driveletters, there is always a risc he may spawn the "Abort, Retry, Fail" message. The info is not a problem, but it can cause the script to hang, and that is an issue.

Report •

#6
February 27, 2010 at 04:28:10
"Be careful that when trying to access certain (unused) driveletters, there is always a risc he may spawn the "Abort, Retry, Fail" message. The info is not a problem, but it can cause the script to hang, and that is an issue."

Dir doesn't induce that problem, my guess is that it calls GetVolumeInformation with SetErrorMode using SEM_FAILCRITICALERRORS(0x0001). Both "GetVolumeInformation" and "SetErrorMode" are visible as plain text inside cmd.exe, presumably as imports.

If the "dir" fails the loop won't execute.


Report •

#7
February 27, 2010 at 04:58:57
You're not an average Windows user, are you ?

Well, now that I think about it, maybe the "Abort, Retry, Fail ?" is something from Windows98 ... ? Haven't seen it lately. But, one should always be careful when testing "special" drives.


Report •

#8
February 27, 2010 at 05:40:50
In xp there is a dialog box version.

If you have a floppy "start a:\"(without a disk). If there is no "a:" then you will get a different dialog box. "dir a:\" will just output an error to the console.


Report •

#9
February 27, 2010 at 06:56:01
Now you made me confuse. However I tried that script and it seems to work fine I didn't receive any error messages even if the drives listed within the script do not exist on my PC. So is it good or no good? :D

Report •

#10
February 27, 2010 at 13:31:56
as long as the system running it is XP or above. my ME box gets the despicable dialogue box Tvc referred to. Once in a blue moon MS actually improves something. Of course, they couldn't resist leaving some mines in the harbour:
IF EXIST A: gets the accursed dialogue, but dir /s a: does not.
it handles the CD drive ok however. Since M2 skipped the floppies, things should be fine.

(where the hell did my first line go? forum-limbo i guess... sorry about that. pre-XP will hang at the cd drive, XP and up won't.)
i couldn't resist...
@goto :10
e100 B4 1C 8A 16 82 00 80 E2 1F CD 21 B4 4C CD 21
rcx
10
nddr.com
w
q
:10
@echo off
if not exist ddr.com debug<drives.bat
if not "%1"=="" goto :yit
for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do call drives %%a
goto :xit
:yit
ddr %1
if not errorlevel 255 echo %1 is ok
:xit


Report •

#11
February 28, 2010 at 03:45:52
> Now you made me confuse. However I tried that
> script and it seems to work fine I didn't receive any
> error messages even if the drives listed within the
> script do not exist on my PC. So is it good or no
> good? :D
>

It's good, as mentioned above, only pre-XP may cause the script to hang ... XP handles it just nicely!


Report •

Ask Question