I'm trying to get my application to create a directory if it doesn't exist, but only if the application isn't running from a floppy drive. I'm making the assumption that drives A: and B: are floppies.
The code I'm using is as follows:
char drive[_MAX_PATH];
char dir[_MAX_DIR];
char filen[_MAX_FNAME];
char ext[_MAX_EXT];
char SourcePath[_MAX_PATH];
_splitpath( ProgramPath, drive, dir, filen, ext );
strcpy( SourcePath, drive );
strcat( SourcePath, dir );
strcat( SourcePath, "SYSBAK" );
if ( toupper( drive[0] ) != 'A' || toupper( drive[0] != 'B' ) {
if ( !FolderExist( SourcePath ) ) {
try {
_mkdir( SourcePath );
}
catch( ... ) {
// do nothing
}
}
}
I have also tried:
if ( stricmp( drive, "A:" ) != 0 || stricmp( drive, "B:" ) != 0 ) {
and:
if ( !(stricmp( drive, "A:" ) == 0) || !(stricmp( drive, "B:" ) == 0) ) {
and yet when I compile and run from a floppy, the directory still gets created. I've confirmed using printf
that drive[0]
is indeed equal to A when running from floppy drive A:. ProgramPath
is defined earlier in the application as argv[0]
.
Can anybody tell me what I'm doing wrong? What is the correct code?
CodePudding user response:
You have "typos", in particular, your ||
should be &&
:
toupper(drive[0]) != 'A' && toupper(drive[0]) != 'B'
which is equivalent to
!(toupper(drive[0]) == 'A' || toupper(drive[0]) == 'B')