Solved: A .bat that reads python files?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Helloher

Thread Starter
Joined
Mar 23, 2010
Messages
18
Does anyone know if a batch file could be created to read python files? What I would like to do is have it read a group of python files in a folder and create a .txt with a piece of information from each one, that is found in the same place on each one. if this is posibble, it would be appreciated.
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
Examples of what is in the python code and what your intended output is would probably help.
 

Helloher

Thread Starter
Joined
Mar 23, 2010
Messages
18
The files vary in complexity, but the barebones file resembles this:

from __future__ import generators
import plus
import Arenas
import random
import Hazards
import math
class Box(Arenas.SuperArena):
"Twiiiiiiiiiiiiiiiisted"
name = "Twiiiiiiiiiiiiiisted Arena"
preview = "twisted/twi_preview.bmp"
game_types = ['DEATHMATCH', 'BATTLE ROYAL', 'TEAM MATCH']
extent = (-15, 15, 15, -15)
def __init__(self):
Arenas.SuperArena.__init__(self, "Arenas/twisted/twisted.gmf")
#plus.Arena.__init__(self, "")
plus.setBackColor(.36, .537, .788)

degrad = 0.01745
self.AddStaticCamera("Battle View", (19.5, 15, 19.5), (50*degrad,225*degrad), 40*degrad)
self.AddStaticCamera("High Flipper View", (-19.5, 45, -19.5), (48*degrad,45*degrad), 84*degrad)
self.AddStaticCamera("Birds Eye View", (0, 45, 0), (90*degrad,0), 50*degrad)
self.AddWatchCamera("Combat Cam", (-12, 8, 12), (16, 36, 65*degrad, 30*degrad))
self.AddWatchCamera("Aerial Cam", (-19.5, 35, -19.5), (50, 60, 45*degrad, 60*degrad))
self.AddWatchCamera("Ground Cam", (8, -5, -8), (15, 40, 75*degrad, 35*degrad))
self.AddWatchCamera("Spectator Cam", (13, 15, 13), (6, 18, 45*degrad, 45*degrad))

self.players = ()
def AddShadowReceivers(self):
self.SetShadowSource(5.897, 19.159, 5.899)

def Activate(self, on):
if on: self.players = plus.getPlayers()

Arenas.SuperArena.Activate(self, on)
def Tick(self):
for each in self.players:
if plus.getLocation(each)[1] < -10: # Adjust this parameter to floor height(s).
plus.eliminatePlayer(each)
return Arenas.SuperArena.Tick(self)

Arenas.register(Box)

All I want to get is the names from each file printed in a .txt, preferably in alphabetical order, although this isn't required.
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
I don't know what you mean by names so you are going to have to be very specific as to what your output would be from this input.
 

Helloher

Thread Starter
Joined
Mar 23, 2010
Messages
18
Where it says name = "Twiiiiiiiiiisted Arena"

I want the name printed in the .txt and nothing else.
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
I am kind of wondering why you can't write this in python if you know how to code python. This is easy enough to do in a batch file though. Will write it up when I am on my lunch break.
 

Helloher

Thread Starter
Joined
Mar 23, 2010
Messages
18
I didn't code this. I simply customised something else. Thanks btw.
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
I think this code should work barring any anomalies with your other files.
Code:
@echo off
setlocal enabledelayedexpansion

:: Output file
Set _oFile=Names.txt

:: Directory with python files
Set _Path=E:\batch files\findstr

:: Used to search and output your files
PushD "%_Path%"
FOR /F "tokens=*" %%I IN ('dir /b /a-d *.py') DO (
	For /F "usebackq tokens=1* delims== " %%a In ("%%I") Do (
		echo.%%a|findstr /B /I /C:"name">nul
		If !errorlevel!==0 echo.%%~b>>%_oFile% 
	)
)
Popd
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
See those two lines of code. The first one is a comment to tell you to set your path to the files.

:: Directory with python files
Set _Path=E:\batch files\findstr
 

Helloher

Thread Starter
Joined
Mar 23, 2010
Messages
18
Hello again. Is there any way to not list specific things? I.E., if 'Practice Arena', or 'Event Results' are found, the file would automatically not list them. However, there is a name called 'The Practice Arena' which I would like to keep. I don't know if this is possible. Thanks.
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
Code:
@echo off
setlocal enabledelayedexpansion

:: Output file
Set _oFile=Names.txt

:: Directory with python files
Set _Path=C:\Users\MaryJo\batch\FindArenaNames

:: Used to search and output your files
PushD "%_Path%"
FOR /F "tokens=*" %%I IN ('dir /b /a-d *.py') DO (
	For /F "tokens=1* delims== " %%a In ('Type "%%I"^|findstr /B /I /C:"name"') Do (
	echo.%%~b|findstr /B /I /V /C:"Practice Arena" /C:"Event Results">nul
	If !errorlevel!==0 echo.%%~b>>%_oFile%
	)
)
PopD
Special thanks to TheOutCaste.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top