Solved

Create a folder monthly

Posted on 1998-07-07
1
225 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now