Simple .bat file help - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming
Click Here to Login
Reply
 
Thread Tools Display Modes
 
Old 01-25-2017, 02:03 PM   #1 (permalink)
The strange one
 
iParanormalx's Avatar
 
Join Date: Aug 2014
Location: US
Posts: 1,101
Default Simple .bat file help

Im doing this for a hilariously dumb reason... but I want to have a really easy way to count how many beers I drink on my Twitch stream.

There are a few simple elements i'm trying to take advantage of here:
  • I can use a .txt file as a source on my broadcast
  • I can add a hot-key to a shortcut in windows such as Shift+F9 which will run a shortcut to said .bat file

What I'm thinking is if i have a text file c:\number.txt and the only thing inside of that text document is a 0 then I could have a simple 2-5 line script that would do something like this:

c:\number.txt + 1 output to > c:\number.txt

I want to take the value that is currently inside of number.txt, add 1 to it, and overwrite that new value into number.txt.

The end result is - every time I open a beer, i'll press Shift+F9 and the broadcast will update how many beers I've been drinking.

Problem is syntax for cmd and math is freaking weird... Here are the sources i've been looking at:

Command Redirection, Pipes | Windows CMD | SS64.com
I'm no programmer... HALP
__________________

__________________

iParanormalx is offline   Reply With Quote
Old 01-25-2017, 02:09 PM   #2 (permalink)
Private Joker
 
carnageX's Avatar
 
Join Date: Feb 2007
Location: South Dakota
Posts: 24,445
Default Re: Simple .bat file help

The top link is for PowerShell operators not batch files.
__________________

__________________
Laptop: MSI GT70 2OC-059us | i7-4700MQ | 16GB | GTX 770m | 500GB SSD / 750GB HDD | 17.3" | Win10 Pro
Desktop: 4690k | 12GB g.Skill RipJaws | GTX 970 | 520hx | Z87X-UD4H | Corsair Vengeance C70 | Corsair H110 | Acer 25" | Acer 22" | Win10
Mobile: Samsung Galaxy Note 5


If I help you, or you just like what I said, rep me by clicking the under my post
carnageX is offline   Reply With Quote
Old 01-25-2017, 02:14 PM   #3 (permalink)
The strange one
 
iParanormalx's Avatar
 
Join Date: Aug 2014
Location: US
Posts: 1,101
Default Re: Simple .bat file help

Thanks for pointing that out
__________________

iParanormalx is offline   Reply With Quote
Old 01-25-2017, 02:32 PM   #4 (permalink)
Private Joker
 
carnageX's Avatar
 
Join Date: Feb 2007
Location: South Dakota
Posts: 24,445
Default Re: Simple .bat file help

So you'd want to read in the # from the text file into a variable, then do your addition, then pipe it back out to the file.

This may help: math - Calculating the sum of two variables in a batch script - Stack Overflow
__________________
Laptop: MSI GT70 2OC-059us | i7-4700MQ | 16GB | GTX 770m | 500GB SSD / 750GB HDD | 17.3" | Win10 Pro
Desktop: 4690k | 12GB g.Skill RipJaws | GTX 970 | 520hx | Z87X-UD4H | Corsair Vengeance C70 | Corsair H110 | Acer 25" | Acer 22" | Win10
Mobile: Samsung Galaxy Note 5


If I help you, or you just like what I said, rep me by clicking the under my post
carnageX is offline   Reply With Quote
Old 01-25-2017, 02:37 PM   #5 (permalink)
The strange one
 
iParanormalx's Avatar
 
Join Date: Aug 2014
Location: US
Posts: 1,101
Default Re: Simple .bat file help

My problem so far is that every time I try to assign the # in the text file to a variable it just assigns the path of the text file to the variable

Code:
SET "number=C:\number.txt"
echo %number%
It just echoes c:\number.txt

If it would assign the # to the variable then I think all i need is

Code:
SET /a "%number%+1" | > %number%
Does it look like i'm at least along the right path?

Thank you Carnage



edit:
I think i found my key
http://stackoverflow.com/questions/3...n-a-batch-file
__________________

iParanormalx is offline   Reply With Quote
Old 01-25-2017, 02:52 PM   #6 (permalink)
The strange one
 
iParanormalx's Avatar
 
Join Date: Aug 2014
Location: US
Posts: 1,101
Default Re: Simple .bat file help

Got it!

Code:
@echo on
set /p number=<C:\number.txt
SET /A newnumber=%number%+1
echo %newnumber% > c:\number.txt
Thank you carnage
__________________

iParanormalx is offline   Reply With Quote
Old 01-25-2017, 02:54 PM   #7 (permalink)
Private Joker
 
carnageX's Avatar
 
Join Date: Feb 2007
Location: South Dakota
Posts: 24,445
Default Re: Simple .bat file help

Nice, good to hear you got it.
__________________
Laptop: MSI GT70 2OC-059us | i7-4700MQ | 16GB | GTX 770m | 500GB SSD / 750GB HDD | 17.3" | Win10 Pro
Desktop: 4690k | 12GB g.Skill RipJaws | GTX 970 | 520hx | Z87X-UD4H | Corsair Vengeance C70 | Corsair H110 | Acer 25" | Acer 22" | Win10
Mobile: Samsung Galaxy Note 5


If I help you, or you just like what I said, rep me by clicking the under my post
carnageX is offline   Reply With Quote
Old 01-25-2017, 03:50 PM   #8 (permalink)
The strange one
 
iParanormalx's Avatar
 
Join Date: Aug 2014
Location: US
Posts: 1,101
Default Re: Simple .bat file help

Friday nights broadcast should get pretty interesting hahahaha
__________________

__________________

iParanormalx is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.bat file help Johnjohnsenson Microsoft Windows and Software 9 05-30-2011 10:19 PM
Moving File Extensions from one location to another?(.bat file assistance) akasixcon Programming 12 11-19-2009 04:12 PM
Making .bat File Need Help Please MackAttack Programming 7 05-10-2006 09:28 PM
Bat File to save file names cjp12711 Programming 1 10-18-2005 01:36 AM
Problems using BAT file to copy file to networked computer Reilly Computer Networking and Internet Hardware 1 07-19-2005 09:04 AM



Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 01:46 AM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.