1.

Solve : How to check the entered path is valid or not?

Answer»

Hi,

THANKS a lot. I have a Question.
I want to check the %1 argument is a valid path or not.

Let us assume my batch file NAME is " print. bat "
i am passing the first argument as C:\temp\data.txt.

d:\print c;\temp\data.txt

suppose if i gave the wrong path by giving " ; "
instead of " : " I have to convey it as wrong path.

HOW TO CHECK THE FIRST ARGUMENT IS A VALID PATH OR NOT?

Regards,
Arjun.
This may help you out:

Code: [Select]
@echo off
if not exist %1 goto error
print %1
goto end
:error
echo put your error message here
:end


Why bother? DOS will be more than happy to point out the error for you.

Hope this helps. HI,

Thanks for the reply. STILL i have some problem.
I want to create a Folder of given path as the %1 argument.

Ex: MD D:\temp

Suppose if i pass the wrong path by giving " ; " instead of " : " the MD creating with the name of only ' D '
not with ' D:\temp ' .

I dont want to create folder with a single letter. If we give wrong path i have to convey as its invalid path.

Can any one help me in this regard?

I want to check the given path is valid or not...how?


Regards,
Arjun.If you are typing the command at the command line, you'll just have to be more careful with your typing as there is no variable that you can intercept and process.

In a batch file, you could do this indirectly by parsing the path as if it were correct and then DISCOVERING it's not...

Code: [Select]
@echo off
for /f "tokens=1-2 delims=:" %%a in ("%1") do (
if .%%b==. goto error
md %1
goto end
)
:error
echo ERROR
:end


Please note that this solution is specific to the example you posted. Contrary to popular belief batch processing is not a programming language; in fact it's not even a good scripting language.

Check out the Script Center for a better set of tools.

Hope this helps.



Discussion

No Comment Found