Computing.Net > Forums > Disk Operating System > Batch files - check directory

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 files - check directory

Reply to Message Icon

Name: avsgunnar
Date: May 26, 2002 at 20:47:18 Pacific
Comment:

I am trying to create batch program that checks for a couple of files before running though. For example, My batch program is dependent on certain files being in a folder which I provide the user. How can I check for the existence of these files if I don't know which drive the folder may be placed.

FOR example...

Every user using my program will already have a folder called FOLDER A. When they download my program, they will place both my batch program & my folder of files(FOLDER B) in their FOLDER A.

The batch program depends on FOLDER B being there. Without having to ask user input which drive FOLDER A is on, is there a way to do a "quick" check.

I know how to check for file in same directory as batch, but this is like a subdirectory check.

Thanks for any info someone can provide. Hopefully this wasn't too confusing.



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: May 27, 2002 at 13:09:46 Pacific
Reply:

Well, yes, it is a little bit confusing hehe.

You want to search the entire drive for a certain folder?? In your example, the batch file was in the same main folder as the folder containing the necessary files. Will that always happen?

Please, explain better the situation. In that example you stated, in order to check if FOLDER B was there, you would do:

if exist "FOLDER B\NUL" echo Folder exists!

But that only checks for the existance of FOLDER B in the current folder, I don't think that's what you want...

Oh, and you want to check for the folder or for the files which are in the folder? And in which OS is that batch supposed to run?

-- Secret_Doom - Leonardo Pignataro --

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


0

Response Number 2
Name: avsgunnar
Date: May 28, 2002 at 21:08:54 Pacific
Reply:

Doom, thanks for the reply. I'll be a bit more specific. Basically, I create graphics enhancements for a program.

Here's the problem. When a user downloads one of my enhancements, he receives a folder of graphics files and my batch program. The user must place the graphics folder into the same location as the program's .exe file. Generally the location should be X:\program\program subfolder\program.exe.

So basically, the folder of graphics I provide need to reside in the same folder as program.exe (ie program subfolder). Now, my batch program exists outside of the graphics folder but also in the same folder as the program.exe (again, program subfolder).

In case I'm losing you - If you opened X:\program\program subfolder you should see my folder of graphics, my batch program, and program.exe

Now, the problem is, the batch file is dependent on my graphics folder containing the correct images (if user renames my folder, or messes w/the graphics either in size or renaming them) my batch program won't run correctly. What I basically need to do is run a quick check to verify that my graphics folder is still present and that my images are intact(at least their names) before the batch program will proceed.

Was this any clearer? Thanks again for any suggestions you can offer.



0

Response Number 3
Name: Secret_Doom
Date: May 29, 2002 at 22:35:07 Pacific
Reply:

Oh yes, this was very much better.

You didn't say what's the name of your folder (the one containing the graphics). Is it variable?? I'll assume it is named "ENHANCE".

This script would check for the filenames, but not for the sizes, though:

@echo off
:: Put the necessary files below
for %%? in (file1.ext file2.ext file3.ext) do if not exist .\ENHANCE\%%? goto error
:: Here goes the main batch
goto eof
:error
echo Error: one or more files is missing.
goto eof
:eof

This another one is a little more complex, but will also check for the sizes:

@echo off
if "%1"=="GoTo:" %1%2
set error=
set dircm$=%dircmd%
set dircmd=
:: Put the necessary files below,
:: with their sizes
call %0 GoTo: check file1.dat 1024
call %0 GoTo: check file2.dat 2048
call %0 GoTo: check file3.dat 512
set dircmd=%dircm$%
set dircm$=
if "%error%"=="" goto ok
set error=
echo Error: one or more files is
echo missing or corrupted.
goto eof
:check
dir .\ENHANCE\%3 |FIND "%4"> nul
if errorlevel=1 set error=1
goto eof
:ok
:: Here goes the main batch
:eof

I hope this is what you need. Please, give me a report back so I know you've read my answer (this post is getting kinda old).

-- Secret_Doom - Leonardo Pignataro --

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


0

Response Number 4
Name: Secret_Doom
Date: May 29, 2002 at 22:42:48 Pacific
Reply:

Hey, the sizes in the second script MUST have the thousand separator:

@echo off
if "%1"=="GoTo:" %1%2
set error=
set dircm$=%dircmd%
set dircmd=
:: Put the necessary files below,
:: with their sizes
call %0 GoTo: check file1.dat 1.024
call %0 GoTo: check file2.dat 2.048
call %0 GoTo: check file3.dat 512
set dircmd=%dircm$%
set dircm$=
if "%error%"=="" goto ok
set error=
echo Error: one or more files is
echo missing or corrupted.
goto eof
:check
dir .\ENHANCE\%3 |FIND "%4"> nul
if errorlevel=1 set error=1
goto eof
:ok
:: Here goes the main batch
:eof

-- Secret_Doom - Leonardo Pignataro --

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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 files - check directory

Batch file, delete directory, NTFS www.computing.net/answers/dos/batch-file-delete-directory-ntfs/10062.html

Can a batch file get a files' date/time stamp? www.computing.net/answers/dos/can-a-batch-file-get-a-files-datetime-stamp/318.html

Can a batch file count directories? www.computing.net/answers/dos/can-a-batch-file-count-directories/7410.html