code

  1. import os  
  2.   
  3. def scanfile(path):  
  4.     filelist = os.listdir(path)  
  5.     allfile = []  
  6.     for filename in filelist:  
  7.         filepath = os.path.join(path,filename)  
  8.         if os.path.isdir(filepath):  
  9.             scanfile(filepath)  
  10.         print filepath   
  11. allfile = scanfile('C:/studyPy')  

 

  1. for path,d,filelist in os.walk("C:/studyPy"):  
  2.     for filename in filelist:  
  3.         os.path.join(path,filename)  
  4. import os    # Import the OS module
    arr = []
    if not os.path.exists('testdir'): # Check to see if it exists
    os.makedirs('testdir') # Create the directory
    print ('1000')
    else:
    for path, d, filelist in os.walk("testdir"):

    for filename in filelist:
    print (os.path.join(path, filename))



    def scanfile(path,arr):
    filelist = os.listdir(path)
    allfile = []
    for filename in filelist:
    filepath = os.path.join(path,filename)
    if os.path.isdir(filepath):
    scanfile(filepath)
    # print (filepath)
    arr.append(filepath)

    allfile = scanfile('testdir',arr)


    for file in arr:
    print("current filepath is : %s"%(file))
posted @ 2017-02-22 16:33  小毛驴  阅读(219)  评论(0编辑  收藏  举报