Solved

Create a folder monthly

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

758 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

18 Experts available now in Live!

Get 1:1 Help Now