python文件和目录
# -*- coding: utf-8 -*-import osdef printFile(rootDir):allFiles = os.listdir(rootDir) #列出文件夹下所有文件和目录for i in range(0, len(allFiles)):# print(rootDir + allFiles[i])path = os.path.join(rootDir, allFiles[i])if not os.path.isfile(path):print(path, " is a directory.")else:print(path, " is a file.")# 得到一个文件夹下面的所有文件,不递归
def getAllFileOfADir(rootDir):fileList = []allFiles = os.listdir(rootDir) #列出文件夹下所有文件和目录for i in range(0, len(allFiles)):# print(rootDir + allFiles[i])path = os.path.join(rootDir, allFiles[i])if not os.path.isfile(path):#print(path, " is a directory.")passelse:#print(path, " is a file.")fileList.append(path)return fileList def printList(l):length = len(l)for i in range(0, length):print(l[i])# recursionDepth为递归的深度,为1时,仅仅查找rootDir目录下的所有指定文件,
# 不再查找子目录
# Suffix为要查找的指定的文件后缀名列表
allFile = [] # global
def getAllFileOfADir(rootDir, recursionDepth, Suffix=None):if(recursionDepth < 0):return#fileList = []allFiles = os.listdir(rootDir) #列出文件夹下所有文件和目录for i in range(0, len(allFiles)):path = os.path.join(rootDir, allFiles[i])if not os.path.isfile(path):if(not(allFiles[i] == '.' or allFiles[i] == '..')):getAllFileOfADir(path + '/', recursionDepth - 1, Suffix)else:if(Suffix != None):for suffix in Suffix:if(allFiles[i].find(suffix) > -1):allFile.append(path)breakelse:allFile.append(path)# python 文件操作,非常方便
def dirOperate():dir1 = "C:/"dir2 = "g:/backUp/"dir3 = "g:/lin"file1 = "g:/people.lxe"file2 = "G:/交通状态/00020时间.xlsx"file3 = "G:/opencv3.4.0.zip"dirList = []dirList.append(dir1)dirList.append(dir2)dirList.append(dir3)fileList = [file1, file2, file3]for dir in dirList:if os.path.exists(dir):print(dir, " exists.")else:print(dir, " doesn't exists.")for file in fileList:if(os.path.exists(file)):print(file, " exist!")else:print(file, " doesn't exists.")print()list_total = [dirList, fileList]for fileSet in list_total:for file in fileSet:if os.path.exists(file):print(file, " exists.")if os.path.isfile(file):print(file, " is a file.")else:print(file, " is a dictory")if os.access(file, os.R_OK):print(file, " is accessible to read.")if os.access(file, os.W_OK):print(file, "is accessible to write.")if os.access(file, os.X_OK):print(file, "is accessible to execute.")else:print(file, " doesn't exists.")# os.rename(), os.remove(), os.move(), os.copy(), os.copytree()def main():rootDir1 = "F:/"#printFile(rootDir1)#file = getAllFileOfADir(rootDir1)#printList(file)#print("Total file: ", len(file))rootDir2 = "F:/2345Downloads/"# getAllFileOfADir(rootDir2, 0)# getAllFileOfADir(rootDir2, 1, ['.exe', '.zip'])# getAllFileOfADir(rootDir2, 2)# printList(allFile)# print("Total file: ", len(allFile))dirOperate()if __name__ == '__main__':main()
相关文章:

你不怕他离职吗?
图片来自“wikiart” 这是我同事在晚上11点多跟我聊微信时问起的一个问题,我觉得这个问题还是挺有代表性的,所以我还是决定就这个问题展开聊聊我对这句话的看法。 我同事之所以这么说,是因为他的组员,也就是问题中的那个他&#x…

tensorflow 1
import tensorflow as tf import numpy as np import matplotlib.pylab as pltdef tfDemo1():#create datax_data np.random.rand(100).astype(np.float32)y_data x_data * 0.1 0.3#create tensorflow structureWeightstf.Variable(tf.random_uniform([1],-1.0,1.0)) #一维&…

SLAM资源整理
资源整理 浙大3D Group VINS orbslam2 orbslam2 video study https://www.bilibili.com/video/BV1bK4y197kB/?spm_id_fromautoNext orbslam2 csdn https://blog.csdn.net/ncepu_chen/category_9874746.html https://www.zhihu.com/column/c_1114864226103037952 https:…

Golang微服务开发实践
github: github.com/yun-mu/Micr… 微服务概念学习:可参考 Nginx 的微服务文章 微服务最佳实践:可参考 微服务最佳实践 demo 简介 服务: consignment-service(货运服务)user-service(用户服务)l…

Linux ssh/scp/docker学习
文章目录Linux ssh/scp/docker使用学习1. ssh 登录2. scp传输文件3. docker4. git checkout 替换指定分支的单个文件Linux ssh/scp/docker使用学习 1. ssh 登录 sudo ssh fireflyip (登录账号密码) scp -r company/data_depthfill/ firefly192.168.105.6:/tmp/ 2…

tensorflow mnist 1
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import keras.backend.tensorflow_backend as KTFdef add_layer(inputs,in_size,out_size,activation_functionNone):#Weights是一个矩阵,[行,列]为[in_size,out_s…

framework7使用笔记
2019独角兽企业重金招聘Python工程师标准>>> myApp.addView(.view-main, {}); 以上这句代码一定要添加 ,否则链接的页面不能正常加载 --------------------------------------------- 如果初始化时定义了preprocess,则页面上链接的自动加载将…

Linux:检查当前运行级别的五种方法
2019独角兽企业重金招聘Python工程师标准>>> 运行级就是Linux操作系统当前正在运行的功能级别。存在七个运行级别,编号从0到6。系统可以引导到任何给定的运行级别。运行级别由数字标识。每个运行级别指定不同的系统配置,并允许访问不同的进程…

概率机器人资料整理
机器人算法仿真 https://atsushisakai.github.io/PythonRobotics/ 最大熵对应的概率分布及其优化推导 https://www.cnblogs.com/yychi/p/9401807.html 矩阵计算网址 http://www.yunsuan.info/matrixcomputations/index.html

LLVM官方文档翻译---- LLVM原子指令与并发指引
英文原文地址:http://llvm.org/docs/Atomics.html 译文原文地址:http://blog.csdn.net/wuhui_gdnt/article/details/52485591 注:该文章转载已经得到译者授权。 --------------------------------------------------------------------------…

matplotlib画图
import matplotlib.pyplot as plt import numpy as npdef test1():# 从[-1,1]中等距去50个数作为x的取值x np.linspace(-1, 1, 50)print(x)y 2*x 1y1 2**x 1# 第一个是横坐标的值,第二个是纵坐标的值plt.plot(x, y)plt.plot(x, y1)# 必要方法,用于将…

学习新对象字面量语法
目标 使用简写属性名称使用简写方法名称使用计算属性名称问题 哪些部分是冗余的? const person{name:name,address:address,sayHello:function(){/*......*/},sayName:function(){/*......*/}sayAddress:function(){/*......*/}} 复制代码简写属性名称 //ES5 const message{te…

ORB-SLAM2代码/流程详解
ORB-SLAM2代码详解 文章目录ORB-SLAM2代码详解1. ORB-SLAM2代码详解01_ORB-SLAM2代码运行流程1 运行官方Demo1.2. 阅读代码之前你应该知道的事情1.2.1 变量命名规则1.3 理解多线程1.3.1 为什么要使用多线程?1.3.2 多线程中的锁1.4 SLAM主类System1.4.1 System类是ORB-SLAM2系统…

VS2010 CUDA 5.5 Win7 64位配置以及项目创建配置
一.安装CUDA5.5以及配置VS助手 1、安装之前必须确认自己电脑的GPU支持CUDA。在设备管理器中找到显示适配器(Display adapters),找到自己电脑的显卡型号,如果包含在http://www.nvidia.com/object/cuda_gpus.html的列表中,说明支持…

HTC VIVE SDK 中的例子 hellovr_opengl 程序流程分析
最近Vive的VR头盔设备很火,恰逢项目需求,所以对 SDK 中的例子 hellovr_opengl 做了比较细致的代码分析,先将流程图绘制如下,便于大家理解。 在ViVe头盔中实现立体效果的技术核心: 如果要外挂Vive的VR设备实现立体效果&…

Proximal Algorithms 4 Algorithms
目录 Proximal minimization解释\(f(x) g(x)\)解释1 最大最小算法不动点解释Forward-backward 迭代解释加速 proximal gradient method交替方向方法 ADMM解释1 自动控制解释2 Augmented Largranians解释3 Flow interpretation解释4 不动点特别的情况 \(f(x) g(Ax)\)Proximal …

C# TripleDES NoPadding 时对待加密内容进行补字节(8个字节为一个Block)
补一个空格(半角): private static byte[] FormatData(String str) {var yu str.Length % 8;if (yu 0) return Encoding.GetEncoding(Consts.Charset).GetBytes(str);var size 8 - yu;var arr new byte[str.Length size];var data Enco…

keras Regressor 回归
import numpy as np np.random.seed(1337) # for reproducibility from keras.models import Sequential from keras.layers import Dense import matplotlib.pyplot as plt # 可视化模块import tensorflow as tf import keras.backend.tensorflow_backend as KTF# create som…

13、JsonResponse响应介绍
转载于:https://blog.51cto.com/yht1990/2406566

keras Classifier 分类
import numpy as np np.random.seed(1337) # for reproducibility from keras.models import Sequential from keras.layers import Dense, Activation from keras.optimizers import RMSprop import matplotlib.pyplot as plt # 可视化模块import tensorflow as tf import ke…

如何管理好自己的性格?
往往因为我们太感性,而获得与男人不一样的灵动的感受。而当过分的感性不合时宜地在职业生涯中表现出来时,我们该怎么调整自己呢? 由于女人与生俱来的特点,我们善良、有耐心,所以我们更易得到别人的支持和帮助&#…

Axis2 webservice入门--Webservice的发布与调用
一、Webservice发布 参考 http://www.cnblogs.com/demingblog/p/3263576.html 二、webservice 调用 部分参考:http://www.cnblogs.com/demingblog/p/3264688.html 使用myeclipse中的axis2插件生成客户端代码 new -->others到如下界面: 点next 到如下界…

Java断点续传(基于socket与RandomAccessFile的实现)
这是一个简单的C/S架构,基本实现思路是将服务器注册至某个空闲端口用来监视并处理每个客户端的传输请求。 客户端先获得用户给予的需传输文件与目标路径,之后根据该文件实例化RandomAccessFile为只读,之后客户端向服务器发送需传输的文件名文…

EJB调用原理分析
EJB调用原理分析 作者:robbin (MSN:robbin_fan AT hotmail DOT com) 版权声明:本文严禁转载,如有转载请求,请和作者联系 一个远程对象至少要包括4个class文件:远程对象;远程对象的接口;实现远程…

Jfinal Generator 不需要生成带某个前缀的表名数组的方法
2019独角兽企业重金招聘Python工程师标准>>> package com.demo.common.model; import javax.sql.DataSource; import com.jfinal.kit.PathKit; import com.jfinal.kit.Prop; import com.jfinal.kit.PropKit; import com.jfinal.plugin.activerecord.generato…

tensorflow 2
import tensorflow as tf import numpy as npdef test1():#create datax_datanp.random.rand(100).astype(np.float32)y_datax_data*0.10.3#create tensorflow structureWeightstf.Variable(tf.random_uniform([1],-1.0,1.0)) #一维,范围[-1,1]biasestf.Variable(tf…

PCB多层线路板打样难点
PCB多层板无论从设计上还是制造上来说,都比单双层板要复杂,一不小心就会遇到一些问题,那在PCB多层线路板打样中我们要规避哪些难点呢? 1、层间对准的难点 由于多层电路板中层数众多,用户对PCB层的校准要求越来越…

GARFIELD@11-07-2004
Vanity Fair转载于:https://www.cnblogs.com/rexhost/archive/2004/11/07/61286.html

python文件读写1
# -*- coding: utf-8 -*-# read txt file def readTextFile(file):f open(file, r)# 尽可能多的读取文件的内容,一般会将整个文件内容都会读取context f.read() print(context)f.close()def readTextFileByLines(file):f open(file, "r")lines f.read…

jfinal框架下使用c3P0连接池连接sql server 2008
2019独角兽企业重金招聘Python工程师标准>>> 闲话少说 进入正题 首先是工程需要的jar包 然后是c3p0的配置文件。我是这样配置的 仅供参考 jdbcDriver com.microsoft.sqlserver.jdbc.SQLServerDriver jdbcUrl jdbc:sqlserver://localhost:7777;databaseNametest us…