Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

DOS BATCH FILE


  • Please log in to reply

#1
stu_design

stu_design

    Member

  • Member
  • PipPipPip
  • 217 posts
ok ive helped some of u in the past, and hopefully u can help me out =D :help: :whistling:

i have a batch file and i need it to del all my temporary files on a given day that can be set up in the batch file. Eventually ill have a program made in VB that will create a batch filke with different parameters that are based on date. Now i have this
@echo off
del C:\temp\*.*


lol, now how do i add this in?
:blink:
if DATE == Tues 05/02/2006 Then del C:\temp*.*

thanks alot that'd be great

Stu
  • 0

Advertisements


#2
amunra

amunra

    Member

  • Member
  • PipPipPip
  • 112 posts
I have not found a way to auto a .bat file yet. I used a .bat file for backing up my webserver before I was able to crack the windows xp pro RAID software so I could use mirroring and block level parity. The best thing I would recommend doing is adding your .bat file as a scheduled task and set the day you want it to delete your temp folder.
  • 0

#3
stu_design

stu_design

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 217 posts
thats what i want to to do
but i need to setup the date idea first
i can do that manually but i want to have it automated in the sense that when it runs in scheduled task, it checks the date and then does an if check based on that

if date equals friday then activate the code

Edited by stu_design, 02 May 2006 - 11:54 PM.

  • 0

#4
gust0208

gust0208

    Member

  • Member
  • PipPipPip
  • 311 posts
Hello,

I will look a bit more once I am back from work, but here are a few links about working with system date/time data with DOS batch files:

http://www.robvander...m/datetime.html
http://www.tech-reci...ng_tips956.html
http://www.chebucto....-Adv.html#CTULD

Hope that helps in the project.

Cheers,
Tom
  • 0

#5
dsenette

dsenette

    Je suis Napol้on!

  • Administrator
  • 26,030 posts
  • MVP
are you wanting it to delete ALL tmp files out of the folder on a specific day (like tuesday) or day of the month (third tuesday)...or are you ONLY wanting it to delete temp files from a specific day and leave the rest in tact?
  • 0

#6
Swandog46

Swandog46

    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP
Well you can always use syntax like:

if "%date%"=="Wed 05/03/2006" goto yes
goto no

:yes
del c:\temp\*.*

:no


but I have a feeling you will actually want to do something more sophisticated, and probably in a better language than batch scripting, as the others have said...
  • 0

#7
amunra

amunra

    Member

  • Member
  • PipPipPip
  • 112 posts

Well you can always use syntax like:

if "%date%"=="Wed 05/03/2006" goto yes
goto no

:yes
del c:\temp\*.*

:no


but I have a feeling you will actually want to do something more sophisticated, and probably in a better language than batch scripting, as the others have said...

That would work, but that does not fix the running of the batch file. In order for this code to work you have to ececute the file, eather by hand or by using scheduled tasks. You can just tell the OS to execute the file on a given day and all you have to add to your file is:
del C:\temp|*.*
this keeps the complicated code down to a minium.
  • 0

#8
skate_punk_21

skate_punk_21

    Malware Removal Expert

  • Retired Staff
  • 1,049 posts

Eventually ill have a program made in VB that will create a batch filke with different parameters that are based on date.

Why not just write the app in VB? :whistling:
  • 0

#9
skate_punk_21

skate_punk_21

    Malware Removal Expert

  • Retired Staff
  • 1,049 posts
Ok, here is what your looking for
@ECHO OFF

if exist %systemdrive%\date.txt for /f "tokens=1,2,3 delims=/" %%a in (%systemdrive%\date.txt) do set mydate=%%a/%%b/%%c
if NOT exist %systemdrive%\date.txt GOTO Choices

set run=False

date /t|Find "%mydate%">nul
IF NOT ERRORLEVEL 1 set run=true

if %run% == true goto CLEANTEMP
if %run% == False goto exit


:Choices
ECHO.
echo				  ษออออออออออออออออออออออออออออออออออป
echo				  บ		TEMP File Remover		 บ
ECHO				  บ		By Skate_Punk_21		  บ
echo				  ฬออออออออออออออออออออออออออออออออออน
echo				  บ 1. Set Date to Run			   บ
echo				  บ 2. run Cleaner Now			   บ
echo				  บ E. Exit without making changes   บ
echo				  ศออออออออออออออออออออออออออออออออออผ
ECHO.
set /p Choice={1,2,E}
if '%Choice%'=='e' GOTO exit
if '%Choice%'=='E' GOTO exit
IF '%Choice%'=='1' GOTO SetRun
IF '%Choice%'=='2' GOTO CLEANTEMP
IF '%Choice%'=='' GOTO exit
GOTO exit


:CLEANTEMP
attrib -s -r -h %systemdrive%\temp\*.*
del /q %systemdrive%\temp\*.*
cls
GOTO Choices


:SetRun
if exist %systemdrive%\date.txt del C:\date.txt
set /p newDate={dd/mm/yyyy}
echo %newDate%>>%systemdrive%\date.txt
ECHO Date Set!

ECHO REGEDIT4>>%systemdrive%\reg.reg
ECHO.>>%systemdrive%\reg.reg
ECHO [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]>>%systemdrive%\reg.reg
ECHO "Punks Temp Cleaner!"="%cd%\clean.bat">>%systemdrive%\reg.reg
regedit /s %systemdrive%\reg.reg
pause
del %systemdrive%\reg.reg
cls
GOTO Choices

:exit
exit
Blurb:
You run it the first time, from whatever directory it will stay in. Once you set the date it should run on, it will edit the registry and run on startup with your computer. If, at the time of running, it is the correct day (as dictated by a text file) it will empty C:\temp\ and present you with the option to set the next date of running. If it is NOT the correct day for temp file cleaning it will close and you'll see nothing.

NOTE: at this line

ECHO "Punks Temp Cleaner!"="%cd%\clean.bat">>%systemdrive%\reg.reg

you'll need to change clean.bat with whatever you will call the file.


and probably in a better language than batch scripting, as the others have said...

Better language?! :help: no wayyyyy! :whistling:

<edit> thats nice code, i might have to copyright it :blink:</edit>

Edited by skate_punk_21, 06 May 2006 - 11:21 PM.

  • 0

#10
stu_design

stu_design

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 217 posts
ty so very much :whistling: skater punk 21 :blink:

lol i was going ANUTS trying to get the whole date thing lol but did EVERYTHING WOW
didn't expect that =D

<edit> thats nice code, i might have to copyright it </edit>


lol you should !!! =D

tysvm and i will keep all updated on progress of me project =D
  • 0

#11
stu_design

stu_design

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 217 posts
hmmm =(
this will work when u run it the VERY first time(where u can set the date and run the cleaner) but it will not run on start up... ive put it physically into the startup folder .... but the batch file just skips through EVEN though is the date that its supposed to run on .... now is there a way to not do it by date .... but to have like a countdown sort of way?

like
in (%systemdrive%\count.txt) do set count=%xx%
set /p count={xx}
count = count - 1 

echo %count%>>%systemdrive%\count.txt

if count <= 1 do CLEANTEMP
if not count <=1 do exit

IN ADVANCE TYVM =D
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP