python+sikuli get file name and number

# -*- coding: utf-8 -*- 

#~ #------------------------------------------------------------------

#~ module:wlab 

#~ Filename:wgetfilelist.py 

#~ Function : 

#~ def IsSubString(SubStrList,Str) 

#~ def GetFileList(FindPath,FlagStr=[]): 

#~ 功能:读取指定目录下特定类型的文件名列表 

#~ Data: 2013-08-08,星期四 

#~ Author:吴徐平 

#~ Email:[email protected] 

#~ #------------------------------------------------------------------

#~ #------------------------------------------------------------------

def IsSubString(SubStrList,Str): 

 ''''' 

 #判断字符串Str是否包含序列SubStrList中的每一个子字符串 

 #>>>SubStrList=['F','EMS','txt'] 

 #>>>Str='F06925EMS91.txt' 

 #>>>IsSubString(SubStrList,Str)#return True (or False) 

 '''

 flag=True

 for substr in SubStrList: 

  if not(substr in Str): 

   flag=False

 return flag 

#~ #---------------------------------------------------------------------- 

def GetFileList(FindPath,FileNum,FlagStr=[]): 

 ''''' 

 #获取目录中指定的文件名 

 #>>>FlagStr=['F','EMS','txt'] #要求文件名称中包含这些字符 

 #>>>FileList=GetFileList(FindPath,FlagStr) # 

 '''

 import os  

 FileList=[] 

 FileNames=os.listdir(FindPath) 

 if (len(FileNames)>0): 

  for fn in FileNames: 

   if (len(FlagStr)>0): 

    #返回指定类型的文件名 

    if (IsSubString(FlagStr,fn)): 

     fullfilename=os.path.join(FindPath,fn) 

     FileList.append(fullfilename) 

     FileNum = FileNum + 1

     popup (fullfilename)

   else: 

    #默认直接返回所有文件名 

    fullfilename=os.path.join(FindPath,fn)      

    FileList.append(fullfilename) 

    #popup ("line 50 : " + fullfilename)

    FileNum = FileNum + 1

    #popup(FileNum)

 #对文件名排序 

 if (len(FileList)>0): 

  FileList.sort() 

 return FileList


#popup(u"please enter your path such as C:\\tools\Sikuli\\ts") 

Filepath = input(u"please enter your path such as C:\\tools\\Sikuli\\ts") 

#popup (Filepath)

FileList = []

FileNum = 0


FileList = GetFileList(Filepath,FileNum,"")

popup (FileList[1] + "filenum")

FileNum = len(FileList)

#Debug_info = "FileNum is :" + FileNum

FileList.append(FileNum) 

popup(FileList[4])


num1 = 0

while FileNum > 0:

    FileNum = FileNum -2

    mum2 = num1 + 1

    

    FileNam1 = FileList[num1]

    popup(FileNam1)

    if FileNam1:

        popup("LINE 78" + FileNam1)

        print(FileNam1)

    else:

        break

    FileNam2 = FileList[num1+1]

    if FileNam2:

        popup("LINE 84" + FileNam2)

        print(FileNam2)

    else:

        break


    mum1 = num1 + 2


    # //do something need while


#end while


你可能感兴趣的:(python)