Thread: creating a new folder at the start of every day

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    108

    creating a new folder at the start of every day

    i guess its pretty self explanatory, i want to be able to create a new folder every day and 00:00:00 hrs.

    the folders have to be named after the day of the year since the 1st of jan. i.s. 15th February would be 46.

    i have the time code:

    Code:
    #include <stdio.h>
    #include <iostream>
    #include <stdlib.h>
    #include <time.h>
    
    int main ()
    
    {
    
    
    using namespace std;
    
          while(true)
          {
              time_t rawtime;  //time since 1st Januay 1970
              time(&rawtime);
              unsigned int clock = rawtime + 7200; // + 7200 for Madrid Time
              unsigned int hour = (clock / 3600) % 24;
              unsigned int minute = (clock % 3600) / 60;
              unsigned int second = clock % 60;
              cout<<hour % 12<<":";
              if(minute < 10)
              {
                  cout<<"0";
              }
              cout<<minute<<":";
              if (second < 10)
              {
                  cout<<"0";
              }
              cout<<second;
              if(hour >= 12)
              {
                  cout<<" P.M."<<endl;
              }
              else
              {
                  cout<<"  A.M. "<<endl;
              }
              system("cls");
          }
          system("pause");
    
      return 0;
    and the directory code.....

    Code:
    	CreateDirectory("c:\\temp\\test", NULL);
    		printf("Directory created\n");
    but i cant get them to link together!!

    dammit!!

  2. #2
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    Put them in the same file and recompile.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    they are in the same file but i have tried doing the the "wait till tenīs of hours turn to zero before making a new folder" trick without sucess!!

  4. #4
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    So what do you mean when you say you can't get them to 'link' together? 'Link' has a very specific and precise meaning in C/C++ compilation.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    108
    sorry,

    i am actually a bit of a newbie.

    what i mean is that i want something that will recognise that the day has changed and will execute the createdirectory command.

    otherwise, the program will skip to the next part (which is to continue writing to a seperate file)

  6. #6
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    First, it is theoretically impossible on a multi-processing OS (essentially everything since DOS and Win3x) to guarentee that your program will run at any given time for any given duration ('preemptive multi-tasking' if you want to google), so you need to look at a range of time large enough so that unless the machine/program is broken you will be sure to fit in (one minute is probably safe) and set a flag to know you are in that zone and whether or not you have created the new file.

    You are mixing C and C++, not a good thing, particularly if you are posting questions on a C board.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by shoobsie
    sorry,

    i am actually a bit of a newbie.

    what i mean is that i want something that will recognise that the day has changed and will execute the createdirectory command.

    otherwise, the program will skip to the next part (which is to continue writing to a seperate file)
    What you are after is something like "if time is 10:00, then create directory".

    Try something like this fragment within your code;
    Code:
    int clock, hour, last_hour = -1;
    
    while(1)
    {
              time_t rawtime;  /* time since 1st Januay 1970 */
              time(&rawtime);
              unsigned int clock = rawtime + 7200; /* + 7200 for Madrid Time */
              unsigned int hour = (clock / 3600) % 24;
              if (hour == 10 && last_hour == 9)   /* assume hour = 10 for 10am */
              {
                   CreateDirectory("C:/temp/test")
              }
              last_hour = hour;
    }
    This will attempt to create a directory every time the hour clicks over from 9 to 10.

    I'll leave specifying the name of the directory as a further exercise.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by mitakeet
    First, it is theoretically impossible on a multi-processing OS (essentially everything since DOS and Win3x) to guarentee that your program will run at any given time for any given duration ('preemptive multi-tasking' if you want to google)
    What you say is true of operating systems such as windows and unix. It is not true of some modern RTOS's (real time operating systems) that are, when suitably configured, able to offer a hard guarantee that specific particular time slices are allocated to specific processes

    Quote Originally Posted by mitakeet
    You are mixing C and C++, not a good thing, particularly if you are posting questions on a C board.
    Agreed.

  9. #9
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    I suspect there are very few RTOS readers at these forums and didn't want to muddy my response.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by mitakeet
    I suspect there are very few RTOS readers at these forums and didn't want to muddy my response.
    Fair enough. I happen to be one of the "very few", so felt an obligation to add mud ....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. day of week
    By s_ny33 in forum C Programming
    Replies: 18
    Last Post: 11-02-2005, 11:56 AM
  2. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  3. creating a text adventure; where to start
    By linucksrox in forum Game Programming
    Replies: 15
    Last Post: 08-23-2005, 02:11 PM
  4. cant get code to work
    By duffy in forum C Programming
    Replies: 13
    Last Post: 10-20-2002, 05:23 AM
  5. Printing weekday
    By sworc66 in forum C Programming
    Replies: 12
    Last Post: 09-13-2002, 07:03 AM