Add folder to XP?

This is a discussion on Add folder to XP? within the Windows Programming forums, part of the Platform Specific Boards category; Help....... I've always used "CreateDirectory()" to make folders but it doesn't seem to work in XP. How would I create ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    7

    Question Add folder to XP?

    Help.......
    I've always used "CreateDirectory()" to make folders but it doesn't seem to work in XP.
    How would I create a new directory in winXP on the c: (root) drive?
    Could I create the folder in C:\Program Files and make it work?
    Any help would really be appreciated.
    Thanks in advance.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    post your code.... CreateDirectory and CreateDirectoryEx work on windows xp.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    7

    Uh Oh

    That means the problem is somewhere else.
    I'll try downloading the newest SDK (56k modem, that's gonna hurt.)
    Here's the code:
    ///////////////////////////////////////////////////////////////////////////////////
    char dbits[100],drive[100];
    int i;
    i=0;
    DWORD d=GetLogicalDriveStrings(10, dbits);
    strncpy(drive,dbits+i,4);

    for (int nDrives = 0; nDrives < 26; nDrives ++)
    {
    if(GetDriveType(drive)==DRIVE_FIXED)
    break;
    i+=4;
    strncpy(drive,dbits+i,4);
    }

    char vol[40];
    DWORD mf;
    DWORD sf,sno;
    char serial[40];

    GetVolumeInformation(drive,
    vol,
    sizeof(vol),
    &sno,
    &mf,
    &sf,
    NULL,NULL);

    _ultoa( sno, serial, 16 );

    char szFindFile[40] = "C:\\Program Files\\FSL\\";
    BOOL MakeSureDirectoryPathExists(*szFindFile);
    if (MakeSureDirectoryPathExists != TRUE)
    {
    CreateDirectory(szFindFile,NULL);
    }
    FILE *fptr;
    fptr = fopen("C:\\Program Files\\FSL\\serial.txt","w");
    fprintf(fptr,"%s\n",serial); // printing the entered name into the file.
    char name[40] = "c:\\Program Files\\FSL\\serial.txt";
    SetFileAttributes(name,FILE_ATTRIBUTE_HIDDEN);
    fclose(fptr);
    ///////////////////////////////////////////////////////////////////////////////////
    Thanks again

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    shouldn't this....

    char szFindFile[40] = "C:\\Program Files\\FSL\\";
    BOOL MakeSureDirectoryPathExists(*szFindFile);
    if (MakeSureDirectoryPathExists != TRUE)
    {
    CreateDirectory(szFindFile,NULL);
    }

    actually be something like this.....

    char szFindFile[40] = "\"C:\\Program Files\\FSL\\\"";
    if (MakeSureDirectoryPathExists(szFindFile) != TRUE)
    {
    CreateDirectory(szFindFile,NULL);
    }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    7

    Talking

    I tried your suggestion but it wouldn't compile.
    I'm pretty sure the first way was correct.
    Thanks for looking it over but I think the problem might be fixed with the new SDK.
    Also, I'm not the one testing this on XP so that is always in question as well.
    Sorry this is looking like a wild goose chase.

  6. #6
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >Could I create the folder in C:/Program Files and make it work?

    If XP is installed on drive C, then you'll have to play around with your security settings as root/Program Files is a protected directory (at least on XP professional using NTFS).

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    I'm pretty sure the first way was correct.
    Erm.... Not a hope!!!

    Look....

    char szFindFile[40] = "C:\\Program Files\\FSL\\";

    the filename has a space in it so you must enclose it in quotes so that the OS doesn't think your filename is c:\Program

    BOOL MakeSureDirectoryPathExists(*szFindFile);

    Doesn't do anything...... its a function prototype..... not needed ..... all api funcs are already prototyped if you include the right headers.

    if (MakeSureDirectoryPathExists != TRUE)

    What path? You are not passing any parameter to MakeSureDirectoryPathExists()
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  8. #8
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Firstly, if you're using MakeSureDirectoryPathExists() you don't need CreateDirectory(). MakeSureDirectoryPathExists() is a debugging function that'll automatically create the directory if it doesn't exist assuming you have sufficient security priviledges.

    Secondly, I don't know what operating system Stoned Coder is using (or what he's been smoking ) but you don't have to do "\"C:\\Program Files\\FSL\\\"", to specifiy a directory path. The below code should create a directory. If this works, but when you try something similar within your Program Files directory it fails then it's a security issue, not a syntax one. You could also try calling GetLastError() which will probably state access denied.

    Code:
    #pragma comment(lib,"Dbghelp.lib")
    
    #include <windows.h>
    #include <dbghelp.h>
    
    int main () 
    {
    
    	char* path = "C:\\Test Dir\\Test Directory\\"; 
    
    	MakeSureDirectoryPathExists(path);
    
    }

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    7

    Talking

    Cool, I might not be an idiot afterall; green as ****, but it sounds like I was on the right track.
    I'm writing and testing this on winME(stop laughing) and VC6 and it's getting tested by another guy on win98, NT4, win2000, and XP pro, so I really have no idea about the security stuff and all he writes back is "works on 98, NT, 2000 but kaks on XP."
    Made the changes (seems like cleaning up redundancies) and I'll fire it off to him and see what happens.
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with program
    By HAssan in forum C Programming
    Replies: 8
    Last Post: 06-10-2007, 09:05 PM
  2. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  3. Upgrading from XP Home to XP Pro
    By kishorepalle in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-11-2004, 10:24 AM
  4. Dual Booting XP and ME
    By doubleanti in forum Tech Board
    Replies: 6
    Last Post: 01-12-2004, 09:25 PM
  5. Progress bars in XP
    By Hunter2 in forum Windows Programming
    Replies: 2
    Last Post: 09-27-2003, 12:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21