我现在有一个包含python文件的文件夹系统py. 在
在同一个文件夹中,我有一个名为“fsys”的文件夹,用于文件系统,我需要检查fsys文件夹中有哪些项目。在
我的问题
如何查看文件夹中的内容并在屏幕上打印?在
二。我如何知道文件夹中的所有内容占用了多少容量并将其打印在屏幕上?在
谢谢!在
编辑:III.我怎样才能使目录列表变成蓝色?在
我的代码如下:
usrn = "user"
cli = "konix>"
st = 1
vs = "Konix One 0.01"
# - System Declarations -
import os
from os import listdir
from os.path import isfile, join
# - Title Declaration -
print "- K O N I X -"
print ""
print "- Konix One 0.01 -"
print ""
# - Command Reading - #
while st == 1:
ucmd = raw_input(cli)
cmd = ucmd.partition(' ')[0]
if cmd == "print" or cmd == "pt":
print ucmd.partition(' ')[2]
if cmd == "version" or cmd == "vs":
print vs
if cmd == "tedit" or cmd == "td":
if ucmd.partition(' ')[2] == "-h" or ucmd.partition(' ')[2] == "-help":
print "Konix Tedit v1.2 Help"
print "To open tedit, type in tedit -u in the console"
print "You should see that your text pointer also has @tedit"
print "To use tedit, first type in text normally."
print "When you are done writing text, create two spaces, put a period, and press enter again."
print "It will show you what you wrote, and you have the option to save or not."
print "Good luck using tedit!"
elif ucmd.partition(' ')[2] == "-u":
input_list = []
while True:
input_str = raw_input("konix@tedit>")
if input_str == "." and input_list[-1] == "":
break
else:
input_list.append(input_str)
for line in input_list:
print line
save = raw_input("Would you like to save this text to your file? [Y/N]: ")
if save == "Y" or save == "y":
name = raw_input("Please enter a name for this file (with .txt at the end): ")
fsys = "fsys/"
fsys += name
filestring = '\n'.join(input_list)
with open(fsys, 'w') as f:
f.write(filestring)
elif save != "N" or save != "n":
print "Not saving"
if cmd == "list" or cmd == "ls":
onlyfiles = [ f for f in listdir("fsys") if isfile(join("fsys",f)) ]
print os.path.join(root, file)
if cmd == "kill" or cmd == "kl":
print "Killing Konix - Farewell!"
st = 0
在iPython里又快又脏让你走。在
要查看子目录中的文件,请从列表中传入子目录。在我的示例中,fsys是一个空目录。见下文:
^{pr2}$现在,说清楚,这又快又脏。你可能不会硬编码你要访问的列表的索引。在
有一个名为glob的python库可以完成这类工作,因此您不必重新发明轮子。它可以列出一个目录中的文件,按扩展名类型进行匹配,等等,这真是太好了。在
相关问题 更多 >
编程相关推荐