You're here: Snippet Directory » C/C++ (495)
Language:

Makes a directory which name containing current time

Language: English
Programming Language: C
Published by: sugaray [not registered]
Last Update: 5/15/2006
Views: 118


Description

just as the title saysand hoping someone could enhance it.

Code

1 //////////////////////////////////////////////////////////////////////////// 2 // MKTDIR.C 3 // 4 // Copyright (C) 2002 Sugar Ray 5 // Version 0.1 6 // 7 // Makes a directory which name containing current time 8 // the name was divided into three parts, the first part is a string 9 // gets from the first parameter passed to the program, the rest 10 // two parts are current date and time. the program replace all the 11 // delimeters in the original string with a underline. 12 // 13 // This program was written and compiled under Microsoft Visual C++ 6.0 14 // You can compile it with other possible compilers (such as Borland C/C++, 15 // GNU C Compiler) with few minor changes to the source. 16 // 17 // This program is free software; you can redistribute it and/or modify 18 // it under the terms of the GNU General Public License as published by 19 // the Free Software Foundation; either version 2 of the License or 20 // (at your option) any later version. 21 //////////////////////////////////////////////////////////////////////////// 22 23 #include <string.h> 24 #include <stdio.h> 25 #include <stdlib.h> 26 #include <direct.h> 27 28 int main(int argc,char **argv) 29 { 30 char Date[9],Time[9]; // strings which store the current date and time 31 char *Ptr; // temporary string pointer 32 char Directory[256],Fuck[256]; 33 const char Pattern[2]="/:"; // all the delimiters 34 unsigned int Status; // status of _mkdir() 35 36 if(argc!=2) // if number of parameters is met 37 { 38 printf("missing required parameter.\n"); 39 printf("Usage:\n\t%s <directory name>\n",argv[0]); 40 exit(1); 41 } 42 43 strcpy(Directory,argv[1]); // get the string from command line 44 45 _strdate(Date); // store current date 46 _strtime(Time); // save current time 47 48 for(Ptr=Date;(Ptr=strpbrk(Ptr,Pattern))!=NULL;*Ptr++='_'); 49 // replace all the delimeters in the original string 50 for(Ptr=Time;(Ptr=strpbrk(Ptr,Pattern))!=NULL;*Ptr++='_'); 51 52 strcpy(Fuck,Date); 53 strcat(Fuck,Time); 54 strcat(Directory,Fuck); // make up the directory name 55 56 Status=_mkdir(Directory); // do it 57 if(Status!=0) // make a fuss if fail 58 { 59 printf("fail to create the directory %s.\n",Directory); 60 exit(1); 61 } 62 63 return 0; // I'm finish. 64 }

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS