Solved

Create a folder monthly

Posted on 1998-07-07
1
260 Views
Last Modified: 2010-04-01
Hi,
  I want to create a folder format by "mm-yy" monthly?
The first thing, I want to check the folder exist or not.
If the folder is not exist then create the folder for the current month.  What's the best way I can do?
Thanks!!
J Chen
0
Comment
Question by:jpchen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 11

Accepted Solution

by:
mikeblas earned 100 total points
ID: 1167343

#include <stdio.h>
#include <time.h>
#include <direct.h>
#include <errno.h>

extern int errno;

int main(int, char*)
{
      time_t t;
      time(&t);
      tm* ptm = localtime(&t);

      char sz[100];
      sprintf(sz, "%2.2d-%2.2d", ptm->tm_mon + 1, ptm->tm_year);

      int nRet = mkdir(sz);
      if (nRet == 0)
            puts("Created successfully.");
      else
            if (errno == EEXIST)
                  puts("Already exists!");

      return nRet;
}


0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

696 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