Thanks for your comment I appreciate it. But i want through automatic batch file not with schedule task.
Main Topics
Browse All TopicsDear Experts..
I need a help from your side. I want to delete some files/ rename some files momentarily (Once a month). For example I need the temporary files deleted once a month automatically. How Can I make a scheduled batch file which will automatically run in each a month.. If I put the command in autoexec.bat, it will run every time when the system started. But I want to run such batch file once a month automatically....
Looking forward for your mails..
Regards
Suzesh
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If you want to run a batch once a month, the only way is to schedule running of the batch to some kind of scheduling software.
The easiest available scheduling software is built in Windows scheduler.
The weak point of this solution is, there could be some opened files in the temporary directory. So, the opened files will not be deleted.
I have a few ideas about how to do it. For an istance: add to autoexec.bat sometching like that:
call clean.bat
del clean.bat
The sheduler instead of cleaning the TEMP directory should copy the clean.bat file to C:\. The next time windows boots clean.bat will be executed once, and then deleted.
So, this is the simplest way to schedule running a batch from autoexec.bat without any additional software, I think.
How about this batch file:
http://www.ericphelps.com/
As far as I understand the BillDL's batch proposition, it is made to run a command if the date is equal to a date remembered in TODAY.INI file.
It will not work, if the computer is not booting every day.
Besides the TODAY.INI file example will not work if used in AUTOEXEC.BAT.
The commands must be in 8.3 format. Long file names are not working before GUI is called.
The easy way to solve that is to use short filenames instead of the long ones given in the example today.ini file. The choice of filename is whatever you specify as long as that file exists.
The names in the .ini file are static. ie. they aren't written to it during daily boots. The current date is ascertained every boot, and ONLY IF it matches any in the .ini file, then the respective .bat file is called. This is a one-time action, and the environment variable only lasts for that session.
I don't follow your reasoning that the computer must be booted every day. The current date is taken every time the computer starts up, and stored as a variable by stripping off the leading text and then storing it as a variable.
After the action is performed, the .ini file is recreated minus the line that triggered it for that day, so if you boot again that day the batch file won't run again.
Normally I test batch files before suggesting them, but I didn't have time on this occasion. I will test it later.
FWIW: Scheduled Task will let you let you set up just about anything you want to run, anyway you want to run it.
Making .BAT file to Delete and Rename is fairly straight forward. It is getting it to run once a month that is the tricky part. Unless you have a overwhelming reason to do it this way, why make life harder than it already is. : )
Thanx for you comment coral47..I appreciate it.
You told "Deleting such files in one month is the tricky part.?" THe main reason is that. I m the computer administrator of the Technical Institute. There are many students who are learning the computer. There period is 3 months. I need to erase all the data once in 3 month. Then If I create the batch file which will help me to delete all unncessary files in absence of me..... thnaks
No, getting a .BAT file to count time is the tricky part. Deleting is easy. Basiclly:
CD <directory you want>
Del *.* <Deletes all files in that Dir>
or
RMDIR (RD) <path to directory you want> <Deletes Dir or SubDir> note: this MUST be run from another dir than the one to be deleted.
Example:
CD D:\Data
Del D:\Data\user\*.*
RD D:\Data\user
Can I point you to a site by a guy named Eric Phelps who has found DOS workarounds for most things, including the use of Times and Dates. That's where the previous batch file link pointed to:
http://www.ericphelps.com/
Take a look at the simple scheduler in which you create your settings in advance into its own .INI file (runs only in Windows though), and a partner program to read or write .INI files from DOS:
http://www.ericphelps.com/
http://www.ericphelps.com/
or the alternative Visual Basic scripting version:
http://www.ericphelps.com/
You can run VB Scripts from DOS using CScript.exe rather than WScript.exe, but that one is a Windows script only.
Some sample batch programs:
http://www.ericphelps.com/
The following trick might prove useful if working with the DATE output in its standard format:
http://www.ericphelps.com/
(Scroll down to the section header "Get Everything Before Something Else")
More links to sites that deal with batch files:
http://www.google.com/sear
suzesh
You can always modify scripts and batch files, that is the idea. It is unlikely that somebody else will already have written a batch file that does exactly what you will be doing, but they should be able to show you the method to make them perform other processes.
So, you want your Temporary files deleted once a month. The "scheduler" program I linked to earlier
http://www.ericphelps.com/
takes its instructions from an .INI file that should be in the same folder as the program file (tiny at 28.5 KB).
YOU write the entries into the INI file telling it what to do, and when to do it. The template INI file will be created if you just double-click the program file (schedule.exe), and then close it using the Task List (Ctrl + Alt + Del).
The template (which I have commented) will specify the program locations, so place it in the folder that you intend running it from so that it creates the correct paths or modify it to suit, eg:
[schedule]
; Alter paths to suit and leave 'logfile' blank for no log
; Change name of logfile or ini file if desired
Program=C:\SCHEDULE\schedu
IniFile=C:\SCHEDULE\schedu
LogFile=C:\SCHEDULE\schedu
CheckPeriod=35
; Number of seconds between checks, change to suit
Below are the sample entries shown in the Readme.txt file that is in included in the download zipfile, but I have modified it slightly.
Scheduled Task [1] is set to run the batch file c:\batch\morning.bat at 7.35 am (07:35) on Monday 1st August 2005
Scheduled Task [2] is set to open the Windows Calculator every 5 minutes after the next shift take over at 6 pm (18:00 hours) on Mondays through to Saturdays (when you don't have to use that computer :-)
Scheduled Task [3] is set to run the batch file c:\batch\tfif.bat at 5.29 pm (17:29 hours) only on Fridays 5th August 2005
Scheduled Task [4] is set to run the batch file c:\batch\hehehe.bat at 11.59 pm (23:59 hours) on Saturday 6th August 2005 (the day after you left the job for a better one and "forgot" to turn the computer off :-)
[1]
Program=c:\batch\morning.b
Year=2005
Month=8
Date=1
Day=Monday
Hour=7
Minute=35
[1]
Program=c:\windows\calc.ex
Year=all
Month=all
Date=all
Day=Monday,Tuesday,Wednesd
Hour=18,19,20,21,22,23,24,
Minute=5,10,15,20,25,30,35
[3]
Program=c:\batch\tfif.bat
Year=2005
Month=August
Date=5
Day=Friday
Hour=17
Minute=29
[4]
Program=c:\batch\hehehe.ba
Year=2005
Month=August
Date=6
Day=Saturday
Hour=23
Minute=59
NOW YOU write the batch files that you have named in your .INI file.
OK, so here's the contents of the batch files that will be called when schedule.exe checks its ini file at the set interval and realises it has to do something:
MORNING.BAT
@echo off
echo. > %TEMP%\resign.txt
echo Dear Boss >> %TEMP%\resign.txt
echo. >> %TEMP%\resign.txt
echo 1st August 2005 >> %TEMP%\resign.txt
echo. >> %TEMP%\resign.txt
echo. >> %TEMP%\resign.txt
echo I resign with effect from Friday 5th August 2005. >> %TEMP%\resign.txt
echo. >> %TEMP%\resign.txt
echo. >> %TEMP%\resign.txt
echo Suzesh >> %TEMP%\resign.txt
c:\windows\notepad.exe /p %TEMP%\resign.txt
exit
TFIF.BAT
@echo off
echo.
echo Friday at last!!
echo.
echo Remember to leave the computer running
echo.
pause
exit
HEHEHE.BAT
@echo off
echo Y > c:\windows\command\script.
echo. >> c:\windows\command\script.
echo type c:\windows\command\script.
c:\windows\rundll32.exe shell32,SHExitWindowsEx 2SHExitWindowsEx 2
So, there we have it. A pretty good scheduler that doesn't show in the System Tray, uses so few resources you don't even know it's running, and it can call program files and launch things like document file types or even url's as long as they have a program associated with them.
The best way to delete TEMP files is by using the Windows 98 Disk Cleanup utility in automated mode from within Windows. To set the options for a batch cleanup job, just open the Start menu's "Run" option, and type the following command (note: the number can be anything from 0 to 65,535, but I have chosen 7):
cleanmgr /sageset:7
or
cleanmgr /d c: /sageset:7
This opens the Windows Disk Cleanup, and you then manually set the options and "Apply" the settings. These are stored in the registry, and you can run the cleanup again using the command:
cleanmgr /sagerun:7
This could be run from the scheduler's INI file using the command above, but you could easily call the following batch file instead. You MAY have to specify the full path to cleanmgr.exe, and will probably need the "start" command in front of it.
@echo off
start cleanmgr /sagerun:7
IF, for some reason there are Temp files that are better deleted before Windows starts up, you can use a batch file to append a line to autoexec.bat specifying a cleanup batch file to be run and then force the system to reboot so that the cleanup batch file is run before windows starts. Let's call the file that will do the cleanup at reboot "RebCln.bat". I'll leave the writing of RebCln.bat up to you, but here's roughly what the other batch file would look like that is called by the scheduler and which then writes the line to autoexec.bat, and forces a reboot:
@echo off
:: make a clean copy of autoexec to restore later
if not exist c:\autoexec.xxx copy c:\autoexec.bat c:\autoexec.xxx
echo call c:\batch\rebcln.bat >> autoexec.bat
c:\windows\rundll32.exe shell32,SHExitWindowsEx 2SHExitWindowsEx 2
The only thing that you would have to add at the very end of your "RebCln.bat" file is a line that restores the backed up autoexec.xxx as autoexec.bat again (ie. the original file without the cleanup line in it):
if exist c:\autoexec.xxx del c:\autoexec.bat
copy c:\autoexec.xxx > c:\autoexec.bat
OR
type c:\autoexec.xxx > c:\autoexec.bat
Now, I provided a link earlier for a batch file named "Today.bat", which For-Soft did not think would work:
http://www.ericphelps.com/
I have tested it on my Windows 98 computer, and it works perfectly. First of all, for this demonstration, create some files in a new folder eg. C:\BATCH:
TODAY.INI
25/06/2004=history.bat
31/07/2005=present.bat
12/09/2006=future.bat
PRESENT.BAT
@echo off
echo.
echo Today is the 31st July 2005
echo present.bat was called from today.ini
echo.
echo press any key to finish
pause>nul
exit
HISTORY.BAT
@echo off
echo.
echo Today is the 25th June 2004
echo (actually, I changed the system date)
echo.
echo history.bat was called from today.ini
echo.
echo press any key to finish
pause>nul
exit
FUTURE.BAT
@echo off
echo.
echo Today is the 12th September 2006
echo (actually, I changed the system date)
echo.
echo future.bat was called from today.ini
echo.
echo press any key to finish
pause>nul
exit
Lastly, create TODAY.BAT, which is the batch file that will act as your calendar/scheduler:
@echo off
:CHECK1
::
:: Check for presence of source file
::
if not exist today.ini goto :MAKEINI
::
:: View and change INI file for testing
:: only. Remove this command in real file.
::
edit today.ini
::
:: Now modify the system date to whichever
:: line in 'Today.ini' you wish to be run.
:: This is only for testing purposes.
:: Remove the following command in the real file.
::
DATE
::
:: Put date into DATE variable
::
@echo.|date|find /i "current">#urrent.bat
@echo set date=%%4>current.bat
call #urrent.bat
del ?urrent.bat
::
:: Put command for today into TODAYSCOMMAND variable
::
find "%date%=" today.ini | sort /r | date | find "=" > en#er.bat
@echo set todayscommand=%%5> enter.bat
call en#er.bat
del en?er.bat > nul
::
:: Cleanup - DATE variable and INI entry
::
type today.ini|find /v "%date%">today.ini
set date=
::
:: The following command is just for demonstration
:: purposes to show you that the correct line was
:: wiped from 'Today.ini'. Remove this section
:: from the real batch file.
::
echo.
echo Today.ini - after line for current date stripped
echo =========
echo.
type today.ini
echo.
echo end of 'Today.ini' press any key to continue ...
pause>nul
::
:: Run today's command and then empty variable
::
call %todayscommand%
set todayscommand=
goto :END
::
:: You will only get here if 'Today.ini'
:: is not in same folder as Today.bat
::
:MAKEINI
echo ??/??/??= > Today.ini
goto :CHECK1
:END
exit
When you run this demonstration, it will open TODAY.INI so you can take note of the dates. Close the DOS Edit window (File > Exit) and it will then run the DATE command. To maintain the current date (31 July 2005 in this demo), just press the ENTER key. To change the date to any other date, just enter it in the format dd-mm-yy and press Enter.
Once done, it will look at the dates in the INI file and compare them against the current system date. If a match is found for any of the lines in the INI file, then the corresponding command on that line will be run. That line is then stripped out of the INI file so that it won't be run again if the batch file is run again that day.
You obviously replace the program to be run on the specific dates with the cleanup batch file, or you could use the cleanmgr /sagerun:x example if being run as Windows loads (ie. from a shortcut in the Start Menu). If being run from a line in autoexec.bat, keep the batch file names short.
Hopefully this explains things in greater detail.
One suggested improvement for that DEMO batch file (Today.bat) where it opens DOS Edit to allow you to add a scheduled task. It's right at the tail-end of the batch file.
:MAKEINI
echo ??/??/????=path and program name to run > Today.ini
goto :CHECK1
:END
exit
It is worthy of note that the original batch file written by Eric Phelps (http://www.ericphelps.com
Current date is Sun 10-12-1997
Enter new date (mm-dd-yy):
I have modified the batch file above to reflect the way MY windows 98se system shows the dates. If I type the DATE command, it shows the following:
Current date is Sun 31/07/2005
Enter new date (dd-mm-yy):
You need to test first to ensure that the format specified in the Today.INI file matches the format that will be generated by the batch file when it uses the DATE command output. My INI file has to specify the date format dd/mm/yyyy because that is what the system generates.
I thought I would just square that up before I am told that it doesn't work. It DOES.
Bill
Let me re-cap on your requirements:
1. You are the administrator of a technical institute
2. Computing students pass through there every three months
3. You would like to schedule a process to run after every 3-month session
4. The process should get rid of all unnecessary files created during that session so that all ther computers are cleaned out and ready for the next batch of students
5. This process should be able to run automatically in your absence.
We have covered some methods where you can easily schedule this process to run at a specific time, day, and date. I am referring to the "schedule.exe" program I spoke about above, where you add separate lines to the program's .INI file.
Say, for instance, that your batch file to do this cleanup operation will be named "CLEANUP.BAT" and will be in the same folder (C:\BATCH) as schedule.exe. Say you have one of those 3-monthly sessions ending on Friday 12th August 2005, and your new students will enrol on Monday 15th August 2005. So you would want the cleanup operation to run at 09:30 on the Monday just after the new students had all powered up their computers and were listening to the Tutor making the introductions.
Ignoring holidays, the next cleanup operations should then be on the following dates to coincide with a new intake of students : Monday 14 November 2005, Monday 13 February 2006, Monday 8 May 2006, and so on.
OK, so your SCHEDULE.INI file would look like this:
14/11/2005=cleanup.bat
13/02/2006=cleanup.bat
08/05/2006=cleanup.bat
Now, that brings us to your CLEANUP.BAT file. It all depends on just what you need to delete. One complication is that, when new students arrive, I presume that they have to set up separate "User Profiles" so that they have to log into Windows 98, and can have their own Desktop layout, their own colour schemes, different Windows Explorer "view" preferences, etc. This would complicate things, because you would have no way of knowing each user name 9 or 12 months ahead. As you will be aware, a Windows 98 "user profile" stores settings for different users of the one computer as:
C:\Windows\Profiles\<usern
where folders like Desktop, Start Menu, Temporary Internet Files, Cookies, History, Recent, etc are all gathered together for each user under their <username> folder.
If all your students are all allocated a SEPARATE computer and DON'T have separate "user profiles", then that makes things a lot easier. You will find some example cleanup batch files here:
http://www.langa.com/clean
Fred Langa is well known, and I have tested a few of these batch files with good success, but batch files like this can damage a computer just as easily as they might successfully delete things, so TEST them on one computer first. Some of these .BAT files MUST ONLY be run from DOS and not from within Windows, or they won't work.
from one of the Experts-Exchange experts:
http://home.ntelos.net/~wr
I'm afraid that actually writing a batch file for YOUR particular situation is a bit beyond the scope of your question which really asked about "how to schedule" a batch file.
Just so that you understand a few concepts used in some of these batch files you will find:
"IF EXIST" folder/file then do something.
You can test for the existence of a folder (evern an empty one) using a command like the following, which would then change directory into the "profiles" folder:
if exist c:\windows\profiles\nul cd c:\windows\profiles
If you just issued the command cd c:\windows\profiles and that folder didn't exist, then it would stop and tell you this, which you don't want.
If you need to check for the existence of files in a certain folder and eg. delete all .txt files from that folder, then you can use the "if exist" test to establish if any exist. For example, if you just issued this command:
del c:\windows\temp\*.txt
but there weren't any .txt files in there, then it would give an error telling you this. Instead, if you issued this command, it would only delete .txt files IF they existed:
if exist c:\windows\temp\*.txt del c:\windows\temp\*.txt
By adding >nul after a command to delete, copy, or other action, it won't show confirmation like eg. 10 file(s) deleted:
if exist c:\windows\temp\*.* del c:\windows\temp\*.*>nul
You can also use the NOT expression in an "if exist" test, eg.
if not exist c:\junk\*.* echo Folder is empty
You can't just delete a folder using the DEL command if it has files or sub-folders in it. The DELTREE command is dangerous, but can be used to wipe out an entire folder and ALL its content. Let's say that a user created a folder named "Stuff" in the c:\my documents folder and it was full of files and sub-folders also with files. You could delete the "Stuff" folder completely using:
DELTREE c:\mydocu~1\stuff
This would prompt you to delete its sub-folders unless you added /Y (which is what makes it dangerous):
DELTREE /Y c:\mydocu~1\stuff
Certain files or folders might only allow themselves to be seen, accessed, or deleted/copie/moved IF you first remove the attributes that normally prevent this. You can SEE a file or folder's attributes by issuing the ATTRIB command eg.
ATTRIB c:\mydocu~1\stuff
ATTRIB c:\mydocu~1\stuff\*.*
Attributes are:
A = Archived
R = Read-Only (will prevent copying, moving, renaming, and deletion)
S = System
H = Hidden (will tell you "file not found" and resists copying, moving, renaming, and deletion).
To REMOVE an attribute, just type a minus before the attribute, and to add the attribute, add a plus. Example, the file c:\mydocu~\stuff\photos\th
attrib -a -h -r c:\mydocu~1\stuff\photos\t
del c:\mydocu~1\stuff\photos\t
deltree /Y c:\mydocu~\stuff
There are some super-hidden files in many of the system folders and user shell folders that can prevent you from deleting content from eg. C:\windows\temporary internet files folder and you usually have to remove their attributes first. Files like index.dat, desktop.ini, and folder.htt are examples of files that are usually +h +r +s.
DOS commands don't like spaces in file or folder names, and think that the space signals the end of the file name, so folders like:
c:\windows\temporary internet files
c:\windows\profiles\bill\s
either have to be enclosed in " "
eg. cd "c:\windows\temporary internet files"
OR abbreviated to their DOS Names
eg. cd c:\windows\tempor~1
Folder names like c:\windows\temporary internet files\content.ie5 can confuse things because the Content.IE5 looks like a file named "content" with the .IE5 file extension.
The best way to see the dos names for files and folders is by either right-clicking on it and looking at the MS-DOS Name under the properties, or by running a DIR command on a folder without any switches, eg: to get a list of ONLY folder names in the "Windows" directory:
DIR /on /ad /p c:\windows
APPLIC~1 = Application Data
DOWNLO~1 = Downloaded Program Files
FAVORI~1= Favorites
STARTM~1= Start Menu
TEMPOR~1 = Temporary Internet Files
etc.
If I were you, I wouldn't be messing arount trying to delete all trash content created by curious students during a 3 month period, because there will be a LOT of junk like files with no extensions saved all over the place.
Have you considered doing this:
1. Fresh installation of Windows 98 configured to suit all users.
2. Make a backup with Microsoft Backup to include everything that it is able to back up. 3. Save it as a file with the .QIC extension to a partition or a folder that won't be accessed.
4. Run the "system recovery" from the Windows CD to restore the system to that state.
Have a look on a Win98 CD in the folder \tools\sysrec and read the document "recover.txt". This explains that the batch file "pcrestor.bat" will do the following:
1. Run setup.exe from the win98 CD and install Windows from the instructions contained in the file "msbatch.inf"
It runs setup with the following options to make it faster and cleaner:
setup.exe c:\restore\msbatch.inf /is /id /iq /im /id /ie /IW, and the instructions in the MSBATCH.INF file make the reinstallation almost completely automated.
2. When it reboots, it will then restore the backup made, so you have a system just about ready to be used by a new user..
You can create your own custom MSBATCH.INF file by installing "MSBATCH" from the folder \tools\reskit\batch, and then use the "gather now" button to get the current settings from a computer with a freshly configured installation of Windows 98.
A better option would be to format the drive each time and then run the system recovery for a totally clean system for each new intake of students.
Hope this helps.
Business Accounts
Answer for Membership
by: coral47Posted on 2005-07-26 at 21:37:03ID: 14533653
To just delete files, you should be able to set up Schedule Task to do this. Start<Programs<Accessories <System Tools<Scheduled Task
If you still need to run a .BAT file for something a little more complex, you should still be able to use it to run the .BAT file. <I need to recheck this, I haven't used it in a while>