[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

bacth file question

dos batch file
not sure if thsi is even possible have looked around on the web and can't seem to find out how to do it. any feed back well appreciated. all i wanna do is check the date a file was created and if it's older than x do something this might make it simpler

batch file

net time \\192.168.0.2 /set /y
net use x: \\192.168.0.2\tbackup
net use y: \\192.168.0.2\mbackup


check date of backup file in mbackup if older than 1 month force backup and place in mbackup

ntbackup backup "C:\documents and settings\%username%" /f "C:\backup\%username%.bkf"



check date of backup in tbackup if older than 5 days ask do they wanna do a backup and place in tbackup


if yes

ntbackup backup "C:\documents and settings\%username%" /f "C:\backup\%username%.bkf"

else
exit


tbackup is temp'e backup
mbackup is monthly backup


cheers in advance

0
jim_bob2003
Asked:
jim_bob2003
  • 2
1 Solution
 
infradawnCommented:
You'll have to do the calendar math yourself but here's the skeleton:

>>>

@echo off
set thefile=temp_script.vbs

rem create datestamp (handles both W2K and 2K3 returned dates)
for /f "tokens=1-3* delims=/ " %%i in ( "%date:~-10%" ) do (
   set nowday=%%i
   set nowmonth=%%j
   set nowyear=%%k
)

rem get file datestamp
for /f "tokens=1-3 delims=/ " %%i in ('dir /tw temp_script.vbs^|find "%thefile%"') do (
   set fileday=%%i
   set filemonth=%%j
   set fileyear=%%k
)

echo %thisfile%
echo File modified: %fileday%/%filemonth%/%fileyear%
echo Today is: %nowday%/%nowmonth%/%nowyear%

set /a yeardiff=%nowyear%-%fileyear%
set /a monthdiff=%nowmonth%-%filemonth%
set /a daydiff=%nowday%-%fileday%

echo Years diff: %yeardiff%
echo Months diff: %monthdiff%
echo Days diff: %daydiff%

pause

<<<


iD
0
 
infradawnCommented:
Oh, should've said: line 2, "temp_script.vbs" is just a test file I pulled the modify date back from while playing with the script.

:)
0
 
jdeclueCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: infradawn {http:#10732297}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

jdeclue
EE Cleanup Volunteer
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now