python查找文件相同的和包含汉字的
#!/usr/bin/env python
# Version = 3.5.2
import os
import time d_path = '/data/media'
log_file = 'result.log' def con_chinese(s):
"""
包含汉字的返回TRUE
:param s: 要判断的字符串
:return: 返回值
"""
for c in s:
if '\u4e00' <= c <= '\u9fa5':
return True
return False def con_zad(s):
"""
只包含字母数字的返回TRUE
:param s: 要判断的字符串
:return: ret
"""
ret = True
for c in s.replace('.', ''):
if 48 <= ord(c) < 128:
pass
else:
ret = False
break
return ret s_time = time.time()
with open(log_file, 'w') as l:
for pathname, dirnames, filenames in os.walk(d_path):
# 查找目录名称相同的或有汉字的
for dir in dirnames:
if con_chinese(dir):
try:
l.write('1--' + os.path.join(pathname, dir) + '\n')
except Exception as e:
l.write('5--' + pathname + str(e) + '\n')
else:
for i in dirnames:
if con_zad(i) and con_zad(dir):
if i.lower() == dir.lower() and i != dir:
try:
l.write('3--' + os.path.join(pathname, dir) + '\n')
break
except Exception as e:
l.write('5--' + pathname + '----' + str(e) + '\n')
# 查找文件名称相同的
for file in filenames:
for x in filenames:
if con_zad(x) and con_zad(file):
if x.lower() == file.lower() and x != file:
try:
l.write('4--' + os.path.join(pathname, x) + '\n')
break
except Exception as e:
l.write('5--' + pathname + '----' + str(e) + '\n') f_time = time.time()
l.write('用时:' + str(f_time-s_time) + '秒\n')
python查找文件相同的和包含汉字的的更多相关文章
- Python查找文件
1. 利用字符串的前缀和后缀匹配查找文件 str.startswith() star.endswith() 2.使用fnmatch fnmatch 判断文件名是否符合特定模式 ...
- python 查找文件内容
输入查找的文件夹路径,要查找的内容关键字(可以指定多个),要查找的文件类型(可以是多个),搜索出符合条件的文件,并记录所有符合条件的行号及行内容. 写的感觉有点冗余,但好歹还能使用^-^,主要是方便手 ...
- Ubuntu 查找文件夹中内容包含关键字的文件,路径为当前文件夹
From CSDN http://blog.csdn.net/lizhenmingdirk/article/details/44834997 grep -rl "keyword" ...
- linux在当前目录下根据文件名查找文件
grep -rl "python" ./ 查找./目录下文件名中包含python的文件 find | grep luoluo将当前目录下(包括子目录)的文件名中含有luoluo的文 ...
- 用 Python 实现文件查找
用 Python 实现文件查找(BIF实现及队列实现) (1)利用内置函数实现文件查找 1.功能:返回用户输入的文件的绝对路径 2.设计思路: (1)用户输入在哪个盘进行查找 (2)遍历此盘文件,若为 ...
- python——根据电子表格的数据自动查找文件
最近刚接触python,找点小任务来练练手,希望自己在实践中不断的锻炼自己解决问题的能力. 经理最近又布置了一个很繁琐的任务给我:有一项很重大的项目做完了,但是要过审计(反正就是类似的审批之类的事情) ...
- 在Linux下查找文件内容包含某个特定字符串的文件
如何在Linux下查找文件内容包含某个特定字符串的文件? 我的目录下面有test1和test2两个文件夹,里面都含有很多文件,其中test2里面还包含一个test文件夹 我想请问的是,如何通过查找关键 ...
- Linux查找文件夹下包含某字符的所有文件
Linux grep 命令用于查找文件里符合条件的字符串.grep 指令用于查找内容包含指定的范本样式的文件,如果发现某文件的内容符合所指定的范本样式,预设 grep 指令会把含有范本样式的那一列显示 ...
- [转帖]linux下查找文件及查找包含指定内容的文件常用命令。
linux下查找文件及查找包含指定内容的文件常用命令. https://blog.csdn.net/yangyu19910407/article/details/18266821 最简单的查找 fin ...
随机推荐
- 并查集实现Tarjan算法
本文是对http://noalgo.info/476.html的一点理解,特别是对其中 int father[mx]: //节点的父亲 int ancestor[mx]; //已访问节点集合的祖先 这 ...
- 杀掉chromedriver.exe进程,防止浪费资源
方法 public void kill_chromedriver(){ Runtime runtime=Runtime.getRuntime(); try{ System.out.println(&q ...
- js禁用后退
history.pushState(null, null, document.URL); window.addEventListener('popstate', function() ...
- thinkphp5 下 的Nginx 伪静态
server { listen 80; server_name all.bjed.com; root "F:\www\asdata"; location / { index ind ...
- Flask第一篇——URL详解
原创 2018-02-14 孟船长 自动化测试实战 URL是Uniform Resource Locator的缩写,即统一资源定位符. 一个URL通常由一下几个部分组成: scheme://host: ...
- 接口测试框架——第二篇-python读取excel文件内容
今天完善excel_module.py文件,上代码: # coding: utf-8 import xlrd class ReadExcel(): def __init__(self, file_na ...
- LeetCode Friend Circles
原题链接在这里:https://leetcode.com/problems/friend-circles/description/ 题目: There are N students in a clas ...
- php array_push 与 $arr[]=$value 性能比较
1.array_push方法 array_push 方法,将一个或多个元素压入数组的末尾. int array_push ( array &$array , mixed $var [, mix ...
- webpack wepack-dev-server 对应版本
webpack wepack-dev-server 对应版本 事情起因是使用 extract-text-webpack-plugin 对 css 和 js 打包进出现 Tapable.plugin i ...
- counting elements--codility
lesson 4: counting elements 1. FrogRiverOne 2. PermCheck 3. MissingInteger 4. MaxCounters lesson 4: ...