LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   delete yesterday's temp files (https://www.linuxquestions.org/questions/programming-9/delete-yesterdays-temp-files-616316/)

Flugelhornchris 01-25-2008 12:19 PM

delete yesterday's temp files
 
Hi, I have a very limited knowledge of programming, but I need to write a program that will go into a particular folder and delete anything in it that was not created the same day the program is run. I need it to be in either c or c++. I'll put this to run everytime someone logs on to the computer so I need it to check the day, not time specifically. Thanks.

theNbomr 01-25-2008 01:42 PM

Since you aren't a programmer (and I don't know why you'd want it in C/C++), how about a cron job that runs every midnight, and deletes everything in the specified directory?
Code:

0 0 * * * rm -rf /the/directory/you/want/to/clean/out
--- rod.

Big_Vern 01-26-2008 04:07 AM

Quote:

Originally Posted by Flugelhornchris (Post 3035211)
Hi, I have a very limited knowledge of programming, but I need to write a program that will go into a particular folder and delete anything in it that was not created the same day the program is run. I need it to be in either c or c++. I'll put this to run everytime someone logs on to the computer so I need it to check the day, not time specifically. Thanks.

Hows about calling somethin like this when the profile is loaded?
Code:

find /the/directory/* -mtime +1 -exec /bin/rm -rf {} \; 2>/dev/null 1>&2

rkelsen 01-26-2008 04:54 AM

Quote:

Originally Posted by Flugelhornchris (Post 3035211)
I need it to be in either c or c++.

Homework question?

Flugelhornchris 01-26-2008 11:50 AM

No, its not a homework question, I took C++ class 6 years ago and don't remember anything except very basic and general information. This is gonna run on a windows machine, they're for the biology lab laptops which students use. We don't leave them running 24/7 and they're not connected to the server so that we can tell them to turn on and run anything at midnight. So I just need a quick program that does the deleting everytime the student turns and logs on the laptop. Trust me if it ran Linux I wouldn't be asking for help, but the school makes the decision on what to run on them not me :(. Thanks a bunch guys.

Flugelhornchris 02-02-2008 04:12 PM

ok it doesn't matter if its c or c++, but I need something that isn't done in a scripting language like perl. I already wrote the program in Perl and I was told it would be best if I didn't write it in as a script. Can anyone help?

theNbomr 02-03-2008 11:48 AM

No one I know would even think of doing such a task in C/C++. Wrong tool for the job. It makes a trivial job into a significant project. There is a reason scripting langugaes like perl were invented, and this is one of them. What reason(s) were you given that C/C++ would be best?
--- rod.

v00d00101 02-03-2008 01:51 PM

Since you dont specify whether windows 9x or NT family, here goes the commands i'd use to torch a folders contents on XP.

Code:

rmdir /q x:\some\folder
md x:\some\folder

How to make it run on login.

http://www.windowsnetworking.com/art.../wxpplogs.html

Flugelhornchris 02-04-2008 12:52 PM

Thanks for the info on making it run on login and how to get rid of the folder. now I need to know how to compare the date stamp on files to todays date (time in hours or seconds not necessary).

The reason for C/C++ is a stupid one: beaurocracy. Everything that goes on the college computers has to be approved by the college, and they don't want to put in a scripting compiler (is it called a compiler?) in the laptops. They already have MS Visual C++ or something MS-ey on them and would rather use that instead. I'm trying my best here come up with the code myself, and I think C++ is giving me more to work with, but I still need help.

Thanks for the patience and time, I really appreciate it.


All times are GMT -5. The time now is 08:45 AM.