This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Using test in Cygwin and Batch-File


On 16 August 2006 23:46, Kai Schlichting wrote:

> Hi!
> I wanna test, if a path in Cygwin exists, and if not, it should be created.
> I tried to write a Batch-File, but dont know how to fill the if statement:
> 
> if not %cygwin%\test -d /myfolder/myfolder2
> 	%cygwin%\mkdir /myfolder/myfolder2
> 
> How would you solve the Problem? I think, its easy for you, but sorry,
> i'm not yet familiar with Unix- and Windows Commandlines...

  There's a couple of ways.

  One would be use a .sh file instead of a .bat, it could say

#!/bin/bash
if [ -d /myfolder/myfolder2 ] ; then
	mkdir /myfolder/myfolder2 
fi

  Your .bat file has a problem, because %cygwin% doesn't refer to the cygwin
install dir, it's the cygwin environment variable settings as described at

http://cygwin.com/cygwin-ug-net/using-cygwinenv.html

  Now, you could always set a variable yourself manually in your environment
variables, say you called it cygdir and it points at your cygwin install
dir... then your batch file should work if you wrote it as

if not %cygdir%\bin\test -d /myfolder/myfolder2
	%cygdir%\bin\mkdir /myfolder/myfolder2


  On the other hand, the mkdir command has an option '-p' which does exactly
what you want anyway: it creates any directories that don't exist and doesn't
error if the directory already does exist, and it can even create all the
directories in a whole path, you can even say "mkdir -p a/b/c/d/e/f/g" and
it'll create them all the way down in one go.  Run "info mkdir" in a cygwin
shell for more.

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]