- Code: Select all
#Windows command line access with python
import os
location=os.path.abspath('test.py')#Where is the file being run from
location=location.replace('\\test.py','')#remove the files name
while True:
temp=raw_input(location+'>')
temp=temp.replace('lolcat', location)#quick add in for current directory
message=temp
if temp=='Exit' or temp=='exit':#exit
break
if temp=='dir' or temp=='ls':#yay added ls
message='dir \"'+location+'\"'
if temp.find('cd')!=(-1):
temp=temp.replace('cd ','')
if temp.find('..')!=(-1):
if temp=='..':#move back a directory(this works)
temp3=location.split('\\')
location=''
for i in range(len(temp3)-1):
location+=temp3[i]+'\\'
location=location[:len(location)-1]
else:#Move back multiple directories(currently doesn't work...Working on it)
temp2=temp.count('..\\')
temp2+=1
temp3=location.split('\\')
location=''
for i in range(len(temp3)-temp2):
location+=temp3[i]+'\\'
location=location[:len(location)-1]
else:
location+='\\'+temp
os.system(message)#use the command
Python 2.6.*
Best results running program not in IDLE




