Solved

make new folder

Posted on 1998-10-28
3
223 Views
Last Modified: 2013-11-20
now i use visual c++5
i would like to know how i create new folder from my application (by write program).
(when i click at button on my dialog in my application it will create new folder for me)
and how to create new text file from my application.
please help me
thank you
0
Comment
Question by:wanlop
  • 2
3 Comments
 

Author Comment

by:wanlop
ID: 1323959
Edited text of question
0
 

Accepted Solution

by:
rakeshkalra earned 100 total points
ID: 1323960
Write the following code in the button click event for creating a directory

if(!CreateDirectory( "c:\\myPreviousDirectory\\MyDirectory", NULL))
{
   // handle error
}

Note that myPreviousDirectory should exist otherwise this call will fail.

Use CStdioFile class for creating a text file.

try
{
    CStdioFile myFile( "c:\\someDir\\MyFile", CFile::modeCreate | CFile::modeWrite | CFile::modeText );

    myFile.WriteString("Hello this is my file\n");
    myFile.WriteString("this is the second line\n");
    myFile.Close();
}
catch(CFileException ex)
{
  // handle exception
}
 

0
 

Expert Comment

by:rakeshkalra
ID: 1323961
Please make the following change in the answer:

Instead of CFile::modeText in

    CStdioFile myFile( "c:\\someDir\\MyFile", CFile::modeCreate | CFile::modeWrite | CFile::modeText );

write CFile::typeText

    CStdioFile myFile( "c:\\someDir\\MyFile", CFile::modeCreate | CFile::modeWrite | CFile::typeText );

Sorry for the mistake.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question