Dear Experienced Users! |
Re: How to check if Directory exists ?
I've found a solution with usage of fileExists_ and the fact, that each directory shall contain the "." (dot) and ".." files: dir= "C:\\Programme\\IBM\\Rational\\DOORS\\lib\\dxl\\addins\\user\\test\\." if (!fileExists_(dir)) print "The folder " dir " does not exists.\n"
|
Re: How to check if Directory exists ? vasgyuszi - Tue Apr 13 07:55:37 EDT 2010
I've found a solution with usage of fileExists_ and the fact, that each directory shall contain the "." (dot) and ".." files: dir= "C:\\Programme\\IBM\\Rational\\DOORS\\lib\\dxl\\addins\\user\\test\\." if (!fileExists_(dir)) print "The folder " dir " does not exists.\n"
Very clever solution!! If you are developing for linux it might fail, since I guess that "." & ".." stuff is only for windows. And since that is a DOS relic you might also want to check that this works for network shares, if you do a library function. Stat s = create "C:\\Windows" if (null s) { print "Not found"; halt } if (directory s) print "Its a directory" else print "No directory?" delete s |
Re: How to check if Directory exists ? Mathias Mamsch - Tue Apr 13 08:23:15 EDT 2010
Very clever solution!! If you are developing for linux it might fail, since I guess that "." & ".." stuff is only for windows. And since that is a DOS relic you might also want to check that this works for network shares, if you do a library function. Stat s = create "C:\\Windows" if (null s) { print "Not found"; halt } if (directory s) print "Its a directory" else print "No directory?" delete s
Thanks Mathias! dir= "C:\\Programme\\IBM\\Rational\\DOORS\\lib\\dxl\\addins\\user\\test\\" if (!fileExists_(dir".")) print "The folder " dir " does not exists.\n" |
Re: How to check if Directory exists ? For example, Stream outF string dirname="c\temp\foldername" string filename="test.txt" if(!fielExists(dir".")) { mkdir(dir, "") outF=write(dirname filename) } else { outF=write(dirname filename) } |
Re: How to check if Directory exists ? These are the two functions I use to figure out if a named Windows string is a file or a directory or neither: //********************* bool fIsFile(string in_NameFile) { // Does the named windows file actually exist. // Name should be fully qualified return(!null in_NameFile and canOpenFile(in_NameFile, false)) } // end fIsFile() //************************** bool fIsDir(string in_NameDir) { // Does the named windows Directory (folder) actually exist. // First, if its actually a file then it isn't a directory Folder if (null in_NameDir or fIsFile(in_NameDir)) return(false) string NameFile = "", ErrMess noError() for NameFile in directory(in_NameDir) do { break } ErrMess = lastError() // Its a directory if there was no DXL error looking at its contents. // if (!null ErrMess) print "\t" in_NameDir "\t" fFormatSysErr(ErrMess) "\n" bool IsDir = (null ErrMess) // print "isDirectory '" in_NameDir "'\t" IsDir "\n" return(IsDir) } // fIsDir()
|