一个在DOS下处理中文和长名字目录和文件的程序(原创)

在DOS下,操作中文目录名和文件名一直是个头疼的问题,如果遇到名字特别长的目录名,则更是困扰,这个程序就是来解决这个问题的。
目前需要改进的地方就是:不知道文件属性的操作。
#  file name : dos.py
#
 -*- coding: utf-8 -*-
'''
This file is to help removing files and directories with long names.

'''
import  os
import  sys



#  change the directory using typing numbers
def  change_directory():
    n 
=   1
    dirlist 
=  []    #  list for directories
    list  =  os.listdir(os.getcwd())
    
print   " parent directory -- 0 "    #  this is for the parent directory
     #  generate directories
     for  one  in  list:
        
if (os.path.isdir(one)):
            
print  one  +   "  --  "   +  str(n)
            dirlist.append(one)
            n 
=  n  +   1
    n 
=  raw_input( " ? " )
    
#  get the directory number that u wanna get in
     try :
        
# if n = 0 , get into the parent directroy
         if (int(n) == 0):
            
try :
                os.chdir(os.pardir)
            
except :
                
print   " there is no parent directory! "
    
except :
        
pass
    
else :
        
try :
            dir 
=  dirlist[int(n) - 1 ]
            os.chdir(dir)
        
except :
            
pass
# this is for removing directory
def  remove_directory():
    n 
=   1
    dirlist 
=  []     # list for directories
    list  =  os.listdir(os.getcwd())
    
# generate directories
     for  one  in  list:
        
if (os.path.isdir(one)):
            
print  one  +   "  --  "   +  str(n)
            dirlist.append(one)
            n 
=  n  +   1
    n 
=  raw_input( " ? " )
    
# get the number of directory u wanna remove
     try :
           dir 
=  dirlist[int(n) - 1 ]
           os.rmdir(dir)
    
except :
        
pass
def  del_file():
    n 
=   1
    filelist 
=  []    # list for files
    list  =  os.listdir(os.getcwd())
    
# generate the file list
     for  one  in  list:
        
if (os.path.isfile(one)):
            
print  one  +   "  --  "   +  str(n)
            filelist.append(one)
            n 
=  n  +   1
    n 
=  raw_input( " ? " )
    
try :
        file 
=  filelist[int(n) - 1 ]
        os.remove(file)
    
except :
        
print   " Error! "
def  show():
    
for  one  in  os.listdir(os.getcwd()):
        
print  one
def  _help():
    
print   " you can type the following commands "
    
print   " cd        change directory "
    
print   " rd        remove directory "
    
print   " del       delete file "
    
print   " show      show files and directories in current directory "
    
print   " help      see this help "
if   __name__ == " __main__ " :
    
while (True):
        command 
=  raw_input( " > " )
        
if  command == " exit " :
            sys.exit(
1 )
        
elif  command  ==   " cd " :
            change_directory()
        
elif  command  ==   " rd " :
            remove_directory()
        
elif  command  ==   " del " :
            del_file()
        
elif  command  ==   " show " :
            show()
        
elif  command  ==   " help " :
            _help()
        
else :
            
continue
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值