LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-27-2008, 02:37 PM   #1
kbartoletta
LQ Newbie
 
Registered: Aug 2008
Posts: 1

Rep: Reputation: 0
a C++ equivilant to mkdir /tmp/directory.$(date +%Y%m%d).$$"


Using "C" - i have a program in which i am trying to create a new output folder to dump the output (a bunch of files) to. I want the new output directory to have a datestamp appended it along with a random identifier.

In bash, I can do this....

mkdir /tmp/directory.$(date +%Y%m%d).$$"

Is there a way to do this within a C program?

***************************
HERE ARE THE VARIABLE DEFINITIONS I AM CURRENTLY USING

const char OUTPUTDIR[]="/tmp/kajun_output/";
char OUTPATH[STRINGLEN];

***********************************
AND HERE IS HOW I AM CURRENTLY MAKING THE DIRECTORY

mkdir(OUTPUTDIR,0777);
 
Old 08-27-2008, 02:50 PM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
'mkdir()' function is correct way of making directories in C. As far as getting date/time data in C, look in the 'time.h' header file documentation ('man time.h'). There are all sorts of functions in there for getting and formatting time.

Good luck.
 
Old 08-27-2008, 04:22 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You can format a time using strftime, then print both the date/time string and the rest of the path to a buffer with snprintf. Lastly, use that buffer as the filename for mkdir.
ta0kira
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to make a directory with mkdir using the date command. Altheastronut Linux - General 5 06-09-2009 12:14 PM
Windows XP batch script - mkdir %date% creates spaces! Micro420 Programming 1 10-19-2006 02:55 AM
can I use date command with mkdir? ewto Linux - General 6 06-16-2004 08:47 AM
"mkdir: cannot create directory `foo': Read-only file system" on FAT32 maddes Linux - Hardware 1 11-26-2003 06:19 PM
"/tmp/sv001.tmp/setup.bin" error while installing OO1.1.0 Choey Linux - Software 0 09-16-2003 04:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration