def get_counts(self, dir=None): collections = 0 images = 0 last_update = None if dir is None: dirs = self.dirs else: dirs = os.listDir(self.get_disk_path(dir)) for item in dirs: if os.path.isdir(self.get_disk_path(item)): collections = collections + 1 images = images + self.get_image_count(item) updated = datetime.datetime.fromtimestamp(os.path.getmtime(self.get_disk_path(item))) if last_update is None or last_update < updated: last_update = updated else: mimetype = mimetypes.guess_type(self.get_disk_path(item))[0] if mimetype is not None and "image" in mimetype: images = images + 1 if last_update is None: # the gallery is empty last_updateFmt = "Never" else: last_updateFmt = last_update.strftime("%x %X") return (collections, images, last_updateFmt)
def batchRenameFile(srcDirName, destDirName): #srcDirName为源文件夹的绝对路径;destDirName为目标文件夹的绝对路径 i = 1; subDirNameList = os.listDir(srcDirName) subDirNameList.sort(key= lambda x:int(x[0:])) # 按照子文件夹名称递增排序 # print(subDirNAmeList) 查看排序结果 for subDirName in subDirNameList: fileList = os.listdir(srcDirName+'/'+subDirName) # 此处给出绝对路径 fileList.sort(key = lambda x:int(x[3:-4])) # 按照文件名字符串中的数字部分(下标由3开始,至倒数第4个字符结束,不含倒数第四个字符)递增排序(这也是同一子文件夹中所有文件的创建顺序) # print(fileList) 查看排序结果 for file in fileList[10::]: #由于每次采集信号是最初采集到的信号不稳定,因此将每次采集到的前10个文件忽略 shutil.copy(srcDirName+'/'+subDirName+'/'+file,destDirName+'/csi'+str(i)+'.dat') #此处给出绝对路径 i=i+1
def createSpectrogram(fileName): files = os.listDir() for file in files: if file.endswith('.mp3'): path = "'" + file try: os.system("sox " + path + "' -n spectrogram -Y 130 -l -r -o " + path[:len(path) - 3] + "png'") except: print(path) print('Error') return
def bunchSave(inputFile, outputFile): catelist = os.listdir(inputFile) bunch = Bunch(target_name=[], lable=[], filenames=[], contents=[]) bunch.target_name.extend(catelist) for eachDir in catelist: eachPath = inputFile + eachDir + "/" fileList = os.listDir(eachPath) for eachFile in fileList: fullName = eachPath + eachFile bunch.label.append(eachDir) bunch.filenames.append(fullName) bunch.contents.append(readFile(fullName).strip()) with open(outputFile, 'wb') as file_obj: pickle.dump(bunch, file_obj)
def get_orphan_groups(self): #FIXME ugly from perroquetlib.repository.exercise_repository_manager import ExerciseRepositoryManager groupPathList = os.listDir(self.get_local_path()) groupUsedPath = [] orphanGroupList = [] for group in self.get_groups(): groupUsedPath.append(group.get_local_path()) for groupPath in groupPathList: if groupPath not in groupUsedPath: #FIXME used or not ??? group = ExerciseRepositoryManager.createGroupFromPath(repoPath) #FIXME repoPath unknow var orphanGroupList.append(group) return orphanGroupList
def getFolderFileList(directory): return os.listDir(directory)
def iterdir(dire, func): for x in listDir(dire): if (isDir(x)): iterdir(x, func) else: func(x)
def getFiles(self): epDir = os.path.join(self.workingDir) dirContent = os.listDir(epDir) fileList = sorted(dirContent) return fileList