Reputation: 11
this is my first question thing so dont judge me too hard.
I'm trying to make a batch file that inputs the PC name, User, date and time into a text (.txt) file. I want/need It to have multiple logs and only In on file.
(the text file will be in the same directory)
Here is what I have done so far and it seems to work for the first 2 (you'll see what I mean) but then it makes another file called 1. I dont know if its my laptop or if its my lack of any coding skill.
@echo off
:make1
if exist "1.txt" goto make2
set SomeVar=%ComputerName% %UserName% %date% %time%
echo %SomeVar% > "1.txt"
exit
:make2
if exist "2.txt" goto make3
ren "1.txt" "2.txt"
echo %SomeVar% >> "2.txt"
exit
:make3
if exist "3.txt" goto make4
ren "2.txt" "3.txt"
echo %SomeVar% >>> "3.txt"
exit
:make4
if exist "4.txt" goto make5
ren "3.txt" "4.txt"
echo %SomeVar% >>>> "4.txt"
exit
:make5
if exist "5.txt" goto make6
ren "4.txt" "5.txt"
set SomeVar=%ComputerName% %UserName% %date% %time%
echo %SomeVar% >>>>> "5.txt"
exit
:make6
set SomeVar=%ComputerName% %UserName% %date% %time%
echo %SomeVar% >>>>>> "6.txt"
pause
exit
I know the last one will be overwritten but i can be bothered adding heaps (also if you have a way of making it infinite it would be greatly appreciated.)
Im making most of my stuff during class at school and I first got into batch about a year ago so sorry for the bad/crude/excessive/annoying code
Thanks, ThePolarBear
Upvotes: 1
Views: 54
Reputation: 96
> mean overwrite entire line
>> append to last line
you don't need to put >>>>>
Upvotes: 1