Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File Question

Status
Not open for further replies.

rhm54

MIS
Sep 5, 2002
59
US
I am attempting to create a batch file that will need to run at the end of every day to grab a file "c:/imagetracII/logs.txt" and save it in another location.

I would like for this batch file to increment each day by placing each days log into a new sub directory. For Example: Day 1 logs are grabbed and sent to c:\logs\logs_07072003\logs.txt and day 2 is c:\logs\logs_07082003\logs.txt. Is there anyway to do this?
 
Check my post on April 4 in thread779-433426, it may help you out.


Marc
[sub]If 'something' 'somewhere' gives 'some' error, expect random guesses or no replies at all. Please specify details.
Free Tip: The F1 Key does NOT destroy your PC!
[/sub]
 
Hi Rhm54,

Using pure batch files there is not to me an obvious way of doing your task, as there is no way of retrieving the components of the date within variables. However, using the KiXtart scripting language ( it is perfectly possible to do this. It is of course possible to run a KiXtart script from within a batch file.

4 hours ago I had never used KiXtart, so those who know it may well know a better way of achieving the same task. This is very much a second program just beyond "Hello world".
Copy and paste the following code into Notepad and save it as MakeFolder.kix (put quotes around the name so Notepad doesn't put a .txt extension on the end).

Code:
; MakeFolder.kix
; KixTart script by John Barnett, 8 July 2003 (handle jrbarnett)
; created for Tek-Tips thread thread616-595635 use KIX32.EXE MakeFolder.kix to run.

DIM $dirname

$DIRNAME = "C:\Logs\Logs_" 

; Build the date up
if @MDAYNO < 10 
  $DIRNAME = $DIRNAME + &quot;0&quot; + @MDAYNO
Else
  $DIRNAME = $DIRNAME + @MDAYNO
EndIf

If @MONTHNO < 10 
  $DIRNAME = $DIRNAME + &quot;0&quot; + @MONTHNO
ELSE
  $DIRNAME = $DIRNAME + @MONTHNO
EndIf
$DIRNAME=$DIRNAME+ @YEAR

; check the directory exists...
if exist ($DIRNAME\nul) = 0
  ; Directory not found - create it
  MD &quot;$Dirname&quot;
EndIf

; check the source file exists
if exist (&quot;c:\imagetracII\logs.txt&quot;) = 1
  Copy (&quot;c:\imagetracII\logs.txt&quot; $DIRNAME)
Else
  MessageBox (&quot;Unable to find source file&quot;, &quot;File Copy&quot;, 0)
EndIf

The only bug I have found in this is that it displays the number &quot;1&quot; at the end of the script in the window it is executed with no obvious explanation, but this is a minor problem.

John
 
Here is batch code to rename a logfile based on the date and time. This should be modifiable to do what you want:


@echo off
setlocal
c:
cd \backuplogs
rem Log File Name changer

if &quot;%1&quot;==&quot;&quot; goto bexit
if not exist &quot;%1log&quot; goto nexit

for /f &quot;tokens=2&quot; %%i in ('date /t') do set DATE_DAY=%%i

for /f %%i in ('echo %date_day:/=_%') do set DATE_DAY=%%i

for /f %%i in ('time /t') do set DATE_TIME=%%i

for /f %%i in ('echo %date_time::=_%') do set DATE_TIME=%%i

copy %1log %DATE_DAY%_%DATE_TIME%_%1%.txt
del &quot;%1log&quot;

:bexit
:nexit
endlocal
c:
cd \batch

HAVE FUN!
 
jimlloyd - can you help with this thread thread621-595772 (as you seem to be a bit of a batch wizard!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top