Computing.Net > Forums > Disk Operating System > Batch file - search for file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file - search for file

Reply to Message Icon

Name: Mike Edwards
Date: November 6, 2002 at 13:43:13 Pacific
OS: Windows 98se
CPU/Ram: 233 / 128mb
Comment:

Hi guys,

Can anyone help me with a batch file that searches a drive for .pst and .dbx files through all dirs, then copies the files it found to a directory?

thanks heaps ,

Mike



Sponsored Link
Ads by Google

Response Number 1
Name: Miskva
Date: November 7, 2002 at 03:49:57 Pacific
Reply:

try this,

dir C:\*.pst /s /b > C:\files.log
dir C:\*.dbx /s /b >> C:\files.log

and then .. hmm, use some editing program to use this file as input to create a batchfile to copy the files to the same dir

thats the way I would do it, edting can be done with awk (non-DOS program)


0

Response Number 2
Name: edwin
Date: November 7, 2002 at 06:40:36 Pacific
Reply:

Miskva is right,
check this one out
http://www.computing.net/dos/wwwboard/forum/12091.html


0

Response Number 3
Name: Secret_Doom
Date: November 7, 2002 at 15:50:26 Pacific
Reply:

Miskva is right about getting the list, but Edwin suggested a solution which I don't know if works, but is definitively dependent on a 3rd party application. That means it won't run in most of the regular Win98 systems, unless you include the 3rd party program together.

That's not necessary. Here's a solution which won't need any 3rd party apps, so should work on most Win98 systems:

===== BATCH SCRIPT BEGIN =====
@echo off

set DEST=X:\Anywere

set DIRBAK=%DIRCMD%
set DIRCMD=
dir/b/s/a-d \*.pst > %TEMP%.\T1.BAT
dir/b/s/a-d \*.dbx >> %TEMP%.\T1.BAT
set DIRCMD=%DIRBAK%
set DIRBAK=

echo e100'SET %%1='> %TEMP%\T3.DAT
for %%? in (rcx 7 w q) do echo %%?>> %TEMP%.\T3.DAT
type nul> %TEMP%.\T2.DAT
DEBUG %TEMP%.\T2.DAT < %TEMP%.\T3.DAT > nul

:loop
copy %TEMP%.\T1.BAT nul > %TEMP%.\T3.DAT
FIND " 0 " < %TEMP%.\T3.DAT > nul
if not errorlevel=1 goto loopend
copy/y %TEMP%.\T2.DAT+%TEMP%.\T1.BAT %TEMP%.\T3.DAT > nul
FIND "SET %%1=" < %TEMP%.\T3.DAT > %TEMP%.\T1.BAT
call %TEMP%.\T1.BAT FILE

copy %FILE% %DEST%

FIND/V "SET %%1=" < %TEMP%.\T3.DAT > %TEMP%.\T1.BAT
goto loop

:loopend
for %%? in (T1.BAT T2.DAT T3.DAT) do del %TEMP%.\%%?
set DEST=
:eof

===== BATCH SCRIPT END =====

That script was extracted from my FAQ #24.

-- Leonardo Pignataro - Secret_Doom --

PS: Hey, Miskva, see the checking for the zero-byte file? =D

secret_doom@hotmail.com
www.batch.hpg.com.br

_____________________________________________________________________


0

Response Number 4
Name: Secret_Doom
Date: November 7, 2002 at 16:01:56 Pacific
Reply:

Hey, I just tested the script and found out a bug, besides the fact that you could run out of enviroment space. Here's the script with the error corrected and which will get more enviroment space:

===== BATCH SCRIPT BEGIN =====
@echo off
if "%1"=="GoTo" goto %2
%comspec% /e:4096 /c %0 GoTo start
goto eof
:start

set DEST=X:\Anywere

set T1=%TEMP%.\T1.BAT
set T2=%TEMP%.\T2.DAT
set T3=%TEMP%.\T3.DAT
set DIRCMD=
dir/b/s/a-d \*.pst > %T1%
dir/b/s/a-d \*.dbx >> %T1%
echo e100'SET %%1='> %TEMP%\T3.DAT
for %%? in (rcx 7 w q) do echo %%?>> %T3%
type nul> %T2%
DEBUG %T2% < %T3% > nul

:loop
copy %T1% nul > %T3%
FIND " 0 " < %T3% > nul
if not errorlevel=1 goto loopend
copy/y %T2%+%T1% %T3% > nul
FIND "SET %%1=" < %T3% > %T1%
call %T1% FILE

copy "%FILE%" "%DEST%"

FIND/V "SET %%1=" < %T3% > %T1%
goto loop

:loopend
for %%? in (%T1% %T2% %T3%) do if exist %%? del %%?

:eof
===== BATCH SCRIPT END =====

That script was designed and tested under Win98SE. It will fail under NT systems. The script won't copy hidden files.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br

_____________________________________________________


0

Response Number 5
Name: Edwin
Date: November 8, 2002 at 04:27:43 Pacific
Reply:

Very nice, very, very nice. Good batch-script


0

Related Posts

See More



Response Number 6
Name: Secret_Doom
Date: November 9, 2002 at 06:35:21 Pacific
Reply:

Thanks. I've found another error: where it says

echo e100'SET %%1='> %TEMP%\T3.DAT

Should be

echo e100'SET %%1='> %T3%

The script still works if T3=%TEMP%.\T3.DAT, but that affects the logic of the script.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch file - search for file

creating a batch file to rename fil www.computing.net/answers/dos/creating-a-batch-file-to-rename-fil/15089.html

Batch files date and time www.computing.net/answers/dos/batch-files-date-and-time/10101.html

batch file to delete .vbs extentions www.computing.net/answers/dos/batch-file-to-delete-vbs-extentions/2895.html