refuses to open file

rbtwms at digitalpath.net rbtwms at digitalpath.net
Thu Apr 18 16:25:15 PDT 2013


Let's start over it has nothing to due with the file.  It's the file name
thats the problem.  I wote a short test program to demenstrate the problem.
It shows that if the file name has a path it causes the exception. i.e:

(prompt)dir
 Volume in drive C is OS
 Volume Serial Number is E221-AB60

 Directory of c:\d\projects\equipment

04/18/2013  03:57 PM             1,070 test.d
               1 File(s)          1,070 bytes
               0 Dir(s)  899,752,787,968 bytes free
(prompt)test 2000 c:\d\projects\equipment\test.d
args.length = 3
out of switch
Type is 2000 case 2
std.exception.ErrnoException at std\stdio.d(289): Cannot open file
`c:\d\projects\eqipment\test.d' in mode `rb' (No such file or directory)
----------------
0x0041A83C
0x0041A6C7
0x0040F577
0x0040B240
0x0040B27A
0x0040AE9C
0x00421F3D
0x752E33AA in BaseThreadInitThunk
0x770C9EF2 in RtlInitializeExceptionChain
0x770C9EC5 in RtlInitializeExceptionChain
----------------
(prompt)test 2000 test.d
out of switch
args.length = 3
out of switch
Type is 2000 case 2
out of switch
args[2] = [test.d]
efile name is File(1F81FE0) case 3
out of switch
out of for
Command line was: ["test", "2000", "test.d"]
File is open

test.d follows:
/* Test program
To test file opening problem
*/
import std.stdio, std.string, std.conv;
void main (string[] args)
{
	auto fname = "l:\\filepro\\mvammach\\key";
  File efile;
  int type;

writeln("args.length = ", args.length);
	if (args.length >= 3){
  	for (int n=1; n <= args.length; n++){
      switch (n){
        case 1:
          break;
        case 2:
          type = to!int( args[1] );
          writefln("Type is %s case 2", type);
          break;
        case 3:
          efile = File(args[2]);
          writefln("args[2] = [%s]", args[2]);
          writefln("efile name is %s case 3", efile);
          break;
        default:
          break;   	
         } // end switch
         writeln("out of switch");
	   } // end for
     writeln("out of for");
   } // end if
   else {
     efile = File(fname,"r");
     writefln("fname = [%s] in else", fname);
		 writefln("efile = [%s]", efile);
   } // end else
writeln("Command line was: ", args[]);
if(efile.isOpen()) writeln ("File is open");
} // end main


More information about the Digitalmars-d-learn mailing list