Board index » cppbuilder » Create a folder using the date as the name

Create a folder using the date as the name


2006-05-04 12:12:39 PM
cppbuilder11
I am trying to figure out how my program can create a folder, using the current date, automatically each day. I have been trying to use the MKDIR function then RENAME the folder to the current date, but with no avail. I am having trouble passing the date, as a name, to the RENAME function. This is what I have so far. I may not even be on the right path, who knows? Thanks.
#define DIRNAME tempchar
tempchar = "date goes here";
mkdir(DIRNAME);
rename(DIRNAME, tempchar);
 
 

Re:Create a folder using the date as the name

The function MoveFile can be used to rename a directory but if you are
creating a folder then there you shouldn't need to create it with one name
and then rename it to what you want. Just use what you want to create it.
Something like this should be close:
#include <windows.h>
#include <dir.h>
void CreateDateDir(void)
{
SYSTEMTIME st;
char dir_name[16];
char drive_letter = (char) ('A' + getdisk());
GetLocalTime(&st);
wsprintf(
dir_name,
"%c:\\%2u-%2u-%4u",
drive_letter, st.wMonth, st.wDay, st.wYear);
mkdir(dir_name); /* could also have used CreateDirectory */
}
. Ed
Quote
Jay wrote in message
news:44597f37$ XXXX@XXXXX.COM ...

I am trying to figure out how my program can create a folder,
using the current date, automatically each day. I have been
trying to use the MKDIR function then RENAME the folder to
the current date, but with no avail. I am having trouble
passing the date, as a name, to the RENAME function. This
is what I have so far. I may not even be on the right path, who
knows? Thanks.

#define DIRNAME tempchar

tempchar = "date goes here";
mkdir(DIRNAME);
rename(DIRNAME, tempchar);
 

Re:Create a folder using the date as the name

On Thu, 4 May 2006 06:22:50 -0400, "Ed Mulroy"
< XXXX@XXXXX.COM >wrote:
Quote
The function MoveFile can be used to rename a directory but if you are
creating a folder then there you shouldn't need to create it with one name
and then rename it to what you want. Just use what you want to create it.
Something like this should be close:

#include <windows.h>
#include <dir.h>

void CreateDateDir(void)
{
SYSTEMTIME st;
char dir_name[16];
char drive_letter = (char) ('A' + getdisk());

GetLocalTime(&st);
wsprintf(
dir_name,
"%c:\\%2u-%2u-%4u",
drive_letter, st.wMonth, st.wDay, st.wYear);

mkdir(dir_name); /* could also have used CreateDirectory */
}

. Ed

>Jay wrote in message
>news:44597f37$ XXXX@XXXXX.COM ...
>
<snip>
Yes, I'd highly recommend you figure out a date format that is legal
for folder names, and useful to your user like Ed did.
Jeff Kish
 

{smallsort}

Re:Create a folder using the date as the name

I posted this earlier, but it was in the wrong group so I
didn't get quite the answer I was looking for. Thanks for the help.
I am trying to figure out how my program can create a folder,
using the current date for it's name, automatically each day. I have been trying to use the MKDIR function but with no avail. I am having trouble passing the date, as a name, to the RENAME function. It seems that the name, when passed to the MKDIR function, must be a const char, and I am not having any luck getting the ever changing date into this format. This is what I have so far. I may not even be on the right path, who knows?
#define DIRNAME tempchar
tempchar = "date goes here";
mkdir(DIRNAME);
Thanks.
 

Re:Create a folder using the date as the name

Jay wrote:
Quote
I posted this earlier, but it was in the wrong group so I
didn't get quite the answer I was looking for. Thanks for the help.

I am trying to figure out how my program can create a folder,
using the current date for it's name, automatically each day. I have been trying to use the MKDIR function but with no avail. I am having trouble passing the date, as a name, to the RENAME function. It seems that the name, when passed to the MKDIR function, must be a const char, and I am not having any luck getting the ever changing date into this format. This is what I have so far. I may not even be on the right path, who knows?


#define DIRNAME tempchar

tempchar = "date goes here";
mkdir(DIRNAME);



Thanks.


AnsiString rtnMsg;
unsigned short uYr, uMo, uDa, uHr, uMn, uSe, uMs;
TDateTime tdt = Now();
tdt.DecodeDate(&uYr, &uMo, &uDa);
tdt.DecodeTime(&uHr, &uMn, &uSe, &uMs);
// Format the date and time any way you want
rtnMsg.sprintf
(
"%02u-%02u-%02u %02u:%02u:%02u.%03u",
uMo, uDa, uYr, uHr, uMn, uSe, uMs
);
CreateDir("C:\\" + xTime);
Hope this helps
Tom Woodrow
 

Re:Create a folder using the date as the name

I am not sure what xTime is in this program.
Thanks
Tom Woodrow < XXXX@XXXXX.COM >wrote:
Quote
Jay wrote:

>I posted this earlier, but it was in the wrong group so I
>didn't get quite the answer I was looking for. Thanks for the help.
>
>I am trying to figure out how my program can create a folder,
>using the current date for it's name, automatically each day. I have been trying to use the MKDIR function but with no avail. I am having trouble passing the date, as a name, to the RENAME function. It seems that the name, when passed to the MKDIR function, must be a const char, and I am not having any luck getting the ever changing date into this format. This is what I have so far. I may not even be on the right path, who knows?
>
>
>#define DIRNAME tempchar
>
>tempchar = "date goes here";
>mkdir(DIRNAME);
>
>
>
>Thanks.
>
>


AnsiString rtnMsg;
unsigned short uYr, uMo, uDa, uHr, uMn, uSe, uMs;
TDateTime tdt = Now();
tdt.DecodeDate(&uYr, &uMo, &uDa);
tdt.DecodeTime(&uHr, &uMn, &uSe, &uMs);

// Format the date and time any way you want
rtnMsg.sprintf
(
"%02u-%02u-%02u %02u:%02u:%02u.%03u",
uMo, uDa, uYr, uHr, uMn, uSe, uMs
);

CreateDir("C:\\" + xTime);

Hope this helps

Tom Woodrow

 

Re:Create a folder using the date as the name

Jay wrote:
Quote
I am not sure what xTime is in this program.
Replace xTime with rtnMsg.
HTH
Jonathan
------------------------
TwineCompiler, blazingly fast C++ compiles on ANY machine:
www.jomitech.com/
------------------------
 

Re:Create a folder using the date as the name

Jay wrote:
Quote
I am not sure what xTime is in this program.

Thanks

Tom Woodrow < XXXX@XXXXX.COM >wrote:

>Jay wrote:
>
>
>>I posted this earlier, but it was in the wrong group so I
>>didn't get quite the answer I was looking for. Thanks for the help.
>>
>>I am trying to figure out how my program can create a folder,
>>using the current date for it's name, automatically each day. I have been trying to use the MKDIR function but with no avail. I am having trouble passing the date, as a name, to the RENAME function. It seems that the name, when passed to the MKDIR function, must be a const char, and I am not having any luck getting the ever changing date into this format. This is what I have so far. I may not even be on the right path, who knows?
>>
>>
>>#define DIRNAME tempchar
>>
>>tempchar = "date goes here";
>>mkdir(DIRNAME);
>>
>>
>>
>>Thanks.
>>
>>
>
>
>AnsiString rtnMsg;
>unsigned short uYr, uMo, uDa, uHr, uMn, uSe, uMs;
>TDateTime tdt = Now();
>tdt.DecodeDate(&uYr, &uMo, &uDa);
>tdt.DecodeTime(&uHr, &uMn, &uSe, &uMs);
>
>// Format the date and time any way you want
>rtnMsg.sprintf
>(
>"%02u-%02u-%02u %02u:%02u:%02u.%03u",
>uMo, uDa, uYr, uHr, uMn, uSe, uMs
>);
>
>CreateDir("C:\\" + xTime);
>
>Hope this helps
>
>Tom Woodrow
>


CreateDir("C:\\" + rtnMsg);
Sorry, I quickly cloned this example from another source file and didn't
edit it very well.
Tom
 

Re:Create a folder using the date as the name

AnsiString TodaysDate,FileDrive = "C:\\"; // replace with appropriate drive
DateTimeToString(TodaysDate, "mmddyyyy", Date()); // replace with
appropriate date format
CreateDir(FileDrive+TodaysDate);
Sudesh
"Jay" < XXXX@XXXXX.COM >wrote in message
Quote

I posted this earlier, but it was in the wrong group so I
didn't get quite the answer I was looking for. Thanks for the help.

I am trying to figure out how my program can create a folder,
using the current date for it's name, automatically each day. I have been
trying to use the MKDIR function but with no avail. I am having trouble
passing the date, as a name, to the RENAME function. It seems that the
name, when passed to the MKDIR function, must be a const char, and I am
not having any luck getting the ever changing date into this format. This
is what I have so far. I may not even be on the right path, who knows?


#define DIRNAME tempchar

tempchar = "date goes here";
mkdir(DIRNAME);



Thanks.