CFile Class Problems

I am using Visual C++ 6 for a project I am working on. I have figured out how to open/read/write to files, but I have a problem. I need to create a directory for files to be written in. I thought it would have created a directory automatically, but that is not the case. How would you create a new subdirectory in Visual C++ with MFC? And help would be much appreciated! Thanks!

Comments

  • : I am using Visual C++ 6 for a project I am working on. I have figured out how to open/read/write to files, but I have a problem. I need to create a directory for files to be written in. I thought it would have created a directory automatically, but that is not the case. How would you create a new subdirectory in Visual C++ with MFC? And help would be much appreciated! Thanks!
    :
    [blue] You have to create them one at a time using this function for Windows os.[/blue]
    [code]
    BOOL CreateDirectoryEx(
    LPCTSTR lpTemplateDirectory, // template directory
    LPCTSTR lpNewDirectory, // directory name
    LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
    );
    [/code]


  • You can use
    [code]
    BOOL CreateDirectory(
    LPCTSTR lpPathName, // pointer to directory path string
    LPSECURITY_ATTRIBUTES lpSecurityAttributes // pointer to security descriptor
    );
    [/code]
    Instead of using CreateDirectoryEx(). This one does not require a string pointing to a template directory.
    [hr]
    When it came down to it I dropped everything and ran.
    -Ramza Final Fantasy Tactics

  • : You can use
    : [code]
    : BOOL CreateDirectory(
    : LPCTSTR lpPathName, // pointer to directory path string
    : LPSECURITY_ATTRIBUTES lpSecurityAttributes // pointer to security descriptor
    : );
    : [/code]
    : Instead of using CreateDirectoryEx(). This one does not require a string pointing to a template directory.
    : [hr]
    : When it came down to it I dropped everything and ran.
    : -Ramza Final Fantasy Tactics
    :
    :
    [blue][b]SHCreateDirectoryEx()[/b] does it using full path name - even creating sub-folders, if they are not there.[/blue]
  • [b][red]This message was edited by pascal.weiss at 2003-9-15 5:24:16[/red][/b][hr]
    What should lpTemplateDirectory have for a value ?
    I don't really understand what it means.


  • : [b][red]This message was edited by pascal.weiss at 2003-9-15 5:24:16[/red][/b][hr]
    : What should lpTemplateDirectory have for a value ?
    : I don't really understand what it means.
    :
    :
    :

    useful only if you want to duplicate directory trees. Use SHCreateDirectoryEx() as AsmGuru62 suggested.
  • : useful only if you want to duplicate directory trees. Use SHCreateDirectoryEx() as AsmGuru62 suggested.

    Neither the compiler nor MSDN seem to know the function.
    Does it require Visual Studio .net ?
    Should I include a specific header or library ?

  • : : useful only if you want to duplicate directory trees. Use SHCreateDirectoryEx() as AsmGuru62 suggested.
    :
    : Neither the compiler nor MSDN seem to know the function.
    : Does it require Visual Studio .net ?
    : Should I include a specific header or library ?
    :
    :


    yes, I get the same results. Searched all the .h files and there is no mention of that function, but it is referenced in the MSDN CD. I can only assume it is part of the Windows SDK that must be installed separately (I don't have it).

    CreateDirectory() will be the next best choice.

  • : I am using Visual C++ 6 for a project I am working on. I have figured out how to open/read/write to files, but I have a problem. I need to create a directory for files to be written in. I thought it would have created a directory automatically, but that is not the case. How would you create a new subdirectory in Visual C++ with MFC? And help would be much appreciated! Thanks!
    :


    What about using plain old _mkdir("dirname");




    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • Hi,

    use the CFile class to create a subdirectory. Since the CFile class does not support subdirectories you may have to build your own class that provides this functionality.
    Regards.
    Alex

    : : I am using Visual C++ 6 for a project I am working on. I have figured out how to open/read/write to files, but I have a problem. I need to create a directory for files to be written in. I thought it would have created a directory automatically, but that is not the case. How would you create a new subdirectory in Visual C++ with MFC? And help would be much appreciated! Thanks!
    : :
    :
    :
    : What about using plain old _mkdir("dirname");
    :
    :
    :
    :
    : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    :
    :

  • : : You can use
    : : [code]:
    : : BOOL CreateDirectory(
    : : LPCTSTR lpPathName, // pointer to directory path string
    : : LPSECURITY_ATTRIBUTES lpSecurityAttributes // pointer to security descriptor
    : : );
    : : [/code]:
    : : Instead of using CreateDirectoryEx(). This one does not require a string pointing to a template directory.
    : : [hr]
    : : When it came down to it I dropped everything and ran.
    : : -Ramza Final Fantasy Tactics
    : :
    : :
    : [blue][b]SHCreateDirectoryEx()[/b] does it using full path name -
    : even creating sub-folders, if they are not there.[/blue]
    :

    How to use this function? Can anybody give a simple example how to use this function to create a directory(for example: like c:abc) because I am a brand new fish in win32 api programming in using vc++ 2005 express version?
    Any hints would be appreciate.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories