-
Mac下解决复制重复文件时,没有像Windows“保留二者”的选项 - Mac文件夹合并,保留重复文件 - xx(1).jpg
2020-03-09 12:48:16你需要在Mac下复制文件到文件夹“B”,但是有部分文件重复了,这时系统没有“保留二者”的选项,只能"跳过","停止","替换",这个简单的要求"保留"为什么不做出来?APP store里面有收费的软件针对这个小问题,¥30...情景
你需要在Mac下复制文件到文件夹“B”,但是有部分文件重复了,这时系统没有“保留二者”的选项,只能"跳过","停止","替换",这个简单的要求"保留"为什么不做出来?APP store里面有收费的软件针对这个小问题,¥30。。。有必要么?
以下脚本是我开发出来,Mac端合并重复文件夹、文件用的,欢迎一起探讨。
效果图「2」
准备材料
- 本工具(mergeFolders.php) https://download.csdn.net/download/qq285744011/12235772
- 桌面新建两个文件夹,from和to,你需要把你要合并的所有文件夹、文件都扔进去from
使用方法
* 【使用方法】
* 1. 在桌面上新建两个文件夹,取名"from"和"to",把你需要合并的文件夹、文件统统复制到文件夹"from"
* 2. 下载本文件"mergeFolders.php"到Macbook上的桌面
* 3. 打开命令行工具 (按F4 > 文件夹"其它" > 终端)
* 4. 在Mac中开启PHP语言支持: https://rudon.blog.csdn.net/article/details/104745975
* 5. 在命令行中,输入命令:php ~/Desktop/mergeFolders.php
* 6. OK, 稍等片刻,检查文件夹"to"是否包含了所有的文件脚本分享
<?php /** * 主题:文件夹合并工具 for Mac, 实现复制文件时"保留两个文件"的效果 * * 作者:Rudon <285744011@qq.com> * 创建:2020-03-09 * 描述: * 在Windows系统下从-文件夹A-复制文件到-文件夹B-时, * 如果文件logo.jpg重复了,系统会在文件夹B里创建文件'logo(1).jpg', * 但是,Mac系统不会,只能"跳过","停止","替换",这个简单的要求"保留"为什么不做出来? * 本工具支持多层文件夹合并。 * * * 【使用方法】 * 1. 在桌面上新建两个文件夹,取名"from"和"to",把你需要合并的文件夹、文件统统复制到文件夹"from" * 2. 下载本文件"mergeFolders.php"到Macbook上的桌面 * 3. 打开命令行工具 (按F4 > 文件夹"其它" > 终端) * 4. 在Mac中开启PHP语言支持: https://rudon.blog.csdn.net/article/details/104745975 * 5. 在命令行中,输入命令:php ~/Desktop/mergeFolders.php * 6. OK, 稍等片刻,检查文件夹"to"是否包含了所有的文件 * */ /* summary.xls => summary(1).xls */ define('SYMBOL_LEFT', '('); define('SYMBOL_RIGHT', ')'); define('FOLDER_FROM', 'from'); define('FOLDER_TO', 'to'); function a ($v){ header('Content-Type: text/css; charset=utf-8'); print_r($v); die(); } $action = new mergeFolder(); $action->merge(); $action->echoResult(); class mergeFolder { public $working_path; public $from; public $to; public $merged_list; public $special_cases; public $need_log; public function __construct() { /* 当前文件夹 */ $this->working_path = dirname(__FILE__).'/'; $this->from = $this->working_path . FOLDER_FROM . '/'; $this->to = $this->working_path . FOLDER_TO . '/'; $this->merged_list = array(); $this->special_cases = array(); $this->need_log = true; $this->check_folders(); } public function check_folders () { if (!is_dir($this->from)) { $this->echoError('找不到文件夹`'.FOLDER_FROM.'`'); } if (!is_dir($this->to)) { $this->echoError('找不到文件夹`'.FOLDER_TO.'`'); } } public function echoError ($message) { die( PHP_EOL .'ERROR: '. $message . PHP_EOL ); } public function get_list_of_files_recursive ($folder) { $return = array(); $folder = rtrim($folder, '/').'/'; if(is_dir($folder)){ $list = scandir($folder); foreach ($list as $oneFile) { if (!preg_match('/^\./', $oneFile)) { /* 除掉那些点号开头的文件 */ if (is_dir($folder. $oneFile)) { $sub_files = $this->get_list_of_files_recursive($folder.$oneFile); $return = array_merge($return, $sub_files); } else { $return[] = $folder . $oneFile; } } } } return $return; } public function merge () { $files = $this->get_list_of_files_recursive($this->from); $counts = count($files); if(!$counts){ $this->echoError('没有任何文件可合并'); } foreach ($files as $k => $one) { /* 对比文件名 */ $file_name = pathinfo($one, PATHINFO_BASENAME); $tobe = $this->to . $file_name; $file_ext = pathinfo($one, PATHINFO_EXTENSION); $file_name_pre = pathinfo($one, PATHINFO_FILENAME); if (!in_array($file_name, $this->merged_list)) { /* 不重复 */ $this->merged_list[] = $file_name; copy($one, $tobe); // 复制 unlink($one); // 删除 } else { $this->log('Repeat: '.$file_name.' in '.$one); /* 重复文件 */ $zuo = SYMBOL_LEFT; $you = SYMBOL_RIGHT; if (!key_exists($file_name, $this->special_cases)) { /* 新猪肉 */ $this->special_cases[$file_name] = 1; } else { /* 旧猪肉 */ $lastNum = $this->special_cases[$file_name]; $newNum = $lastNum + 1; $this->special_cases[$file_name] = $newNum; } $repeat_num = $this->special_cases[$file_name]; $file_name_new = $file_name_pre.$zuo.$repeat_num.$you.'.'.$file_ext; $this->log('Repeat: '.$file_name.' [Repeat] '.$repeat_num); $this->log('Repeat: '.$file_name.' [To Be] '.$file_name_new); while (in_array($file_name_new, $this->merged_list)) { $this->log('Repeat: '.$file_name.' [Exists in Target folder] yes'); $repeat_num++; $this->special_cases[$file_name] = $repeat_num; $file_name_new = $file_name_pre.$zuo.$repeat_num.$you.'.'.$file_ext; $this->log('Repeat: '.$file_name.' [New Repeat] '.$repeat_num); $this->log('Repeat: '.$file_name.' [New To Be] '.$file_name_new); } $this->merged_list[] = $file_name_new; copy($one, $this->to . $file_name_new); // 复制 unlink($one); // 删除 $this->log('Repeat: '.$file_name.' [Done] '); } } } public function log ($mess) { if ($this->need_log) { echo PHP_EOL.'[DEV] '.$mess.PHP_EOL; } } public function echoResult () { die( PHP_EOL .'成功!其中重复文件共有'. count($this->special_cases) .'组' . PHP_EOL ); } } /* End of CLASS */
-
bat批处理文件实现复制、删除、创建文件夹、执行程序、打开文件
2014-12-15 12:28:404、还有一种情况我们经常也碰到的,因为复制某个文件出错或者这个文件在使用中,而停止了复制工作,(比如,复制C 盘上的 windows xp )我们这时候想跳过某个出错的文件和某个正在使用中文件而继续复制其他文件。... -
maven的优缺点 项目
2017-06-23 17:50:59千万不要将文档中的setting的内容全部替换到maven中的内容,要对比着修改,保留原来的; 只修改本地仓库,和下载镜像(源) 3.2.Eclipse Maven的配置 每打开一个新的工作空间,要配置一下Maven,然后再写代码 3.3.创建... -
NLP之昆虫词典制作
2019-11-30 21:36:43读取文本,将句号替换成换行,跳过空行 通过自建筛选字典和清华动物字典,对文本进行处理,保留每行含有动物词汇的行 按照7:3的比例,划分训练集和测试集 读取训练集,生成昆虫领域词典。...本次NLP作业需要每个人在小组选定领域下进行子领域词典制作,我们小组选定的领域为动物。我个人选定的子领域为昆虫,原始语料库来自《昆虫记》这本书。通过爬虫或者复制粘贴可以在本地得到关于《昆虫记》的文本文件。
数据的处理
- 读取文本,将句号替换成换行,跳过空行
- 通过自建筛选字典和清华动物字典,对文本进行处理,保留每行含有动物词汇的行
- 按照7:3的比例,划分训练集和测试集
- 读取训练集,生成昆虫领域词典。(most_common可以指定返回数目,因为有些动物名只出现一次,并且生成词典较小。所以这里并未指定,而是全部返回,然后人工筛选)
- 用jeiba对训练集进行分词处理
评估
中文分词系统的评价指标一般有切分准确率(Precision)、召回率(Recall)、分词精度(F1-Measure)等。本实验将F1作为评测指标来评价HMM模型对昆虫领域的分词效果,F1的计算公式如下所示:
python程序
import os import sys import random import json import jieba import jieba.posseg from collections import Counter class ProcessData(object): def __init__(self, *dic_path): self.dictionary = set() self.maximum = 0 # 加载词典 for path in dic_path: self.load_dic(path) # 加载字典 def load_dic(self, dic_path): with open(dic_path, 'r', encoding='utf-8') as fp: for line in fp: line = line.strip().split()[0] if not line: continue self.dictionary.add(line) self.maximum = max(self.maximum, len(line)) # 判断text中是否包含词典中的词 def return_data(self, text): index = 0 while index < len(text): match = False for size in range(self.maximum, 0, -1): if index + size > len(text): continue piece = text[index:(index + size)] if piece in self.dictionary: return True if not match: index += 1 return False # 划分数据集和测试集 def train_test_split(self, data_path, train_path, test_path): try: with open(data_path, 'r', encoding='utf-8') as fp, open( train_path, 'w', encoding='utf-8') as train, open(test_path, 'w', encoding='utf-8') as test: lines = fp.readlines() threshold = int(len(lines) * 0.7) random.shuffle(lines) for i, line in enumerate(lines): if i < threshold: train.write(line) else: test.write(line) except Exception: print(sys.stderr, "文件读写出现错误") raise Exception sys.exit(1) # 对text文件进行词性标注 def postag_txt(self, inputFile, outputFile): with open(inputFile, 'r', encoding="utf-8") as fin, open(outputFile, 'w+', encoding="utf-8", newline='') as fout: # 词性统计 d = {} for eachLine in fin: # 跳过空行 if not len(eachLine.strip()): continue else: line = eachLine.strip().replace('。', os.linesep) # 使用jieba词性标注 posLine = jieba.posseg.cut(line) newLine = '' for key in posLine: # newLine += "{}/{} ".format(key.word, key.flag) d[key.flag] = d.get(key.flag, 0) + 1 # fout.write(newLine + os.linesep) fout.write(json.dumps(d)) return True # 词频统计 def count_words(self, text): # 加载停用词表 stop_path = os.path.join(sys.path[0], r'.\data\stop_words.utf8') stopwords = [ line.strip() for line in open(stop_path, 'r', encoding='utf-8').readlines() ] seg_list = jieba.cut(text) c = Counter() for word in seg_list: if word not in stopwords and len(word) > 1 and word != os.linesep: c[word] += 1 # 前count lines = "" for (word, num) in c.most_common(): line = word + " " + str(num) + os.linesep lines += line return lines # jeiba分词 def seq_word(self, input_path, output_path): with open(input_path, 'r', encoding='utf-8') as fin, open(output_path, 'w', encoding='utf-8') as fout: for line in fin.readlines(): seq_list = jieba.cut(line, cut_all=False) fout.write(' '.join(seq_list)) print("jeiba分词完成") def Process(): dict1_path = os.path.join(sys.path[0], r'.\data\THUOCL_animal.txt') # 清华动物词典 dict2_path = os.path.join(sys.path[0], r'.\data\my_animal.txt') # 自建词典 input_path = os.path.join(sys.path[0], r'.\data\insect_origin.txt') output_path = os.path.join(sys.path[0], r'.\data\insect.txt') train_path = os.path.join(sys.path[0], r'.\data\train_insect.txt') # 生成训练集路径 test_path = os.path.join(sys.path[0], r'.\data\test_insect.txt') # 生成测试集路径 pro = ProcessData(dict1_path, dict2_path) # 加载词典 try: with open(input_path, 'r', encoding='utf-8') as input_text, open(output_path, 'w', encoding='utf-8', newline='') as output: for line in input_text: flag = pro.return_data(line.strip()) if flag: print("line:", line) output.write(line) except Exception: print(sys.stderr, "文件打开错误") raise Exception sys.exit(1) print("数据处理完成") pro.train_test_split(output_path, train_path, test_path) print("训练集和测试集生成") my_dict = os.path.join(sys.path[0], r'.\data\my_dict.txt') # 词典生成 with open(train_path, 'r', encoding='utf-8') as fin, open(my_dict, 'w', encoding='utf-8', newline="") as fout: text = fin.read() text = pro.count_words(text) fout.write(text) # 用jeiba对训练集进行分词处理 jieba_train = os.path.join(sys.path[0], r'.\data\jieba_train.txt') pro.seq_word(train_path, jieba_train) # 用jeiba对测试集进行分词处理 jieba_train = os.path.join(sys.path[0], r'.\data\jieba_test.txt') pro.seq_word(test_path, jieba_train) output_tag = os.path.join(sys.path[0], r'.\data\train_tag.txt') pro.postag_txt(train_path, output_tag) # F1值计算 def estimate_F1(): # 评估分词模型的准确率 hmm_path = r'.\data\hmm_output.txt' jieba_path = r'.\data\jieba_test.txt' with open(hmm_path, 'r', encoding='utf-8') as f_hmm, open(jieba_path, 'r', encoding='utf-8') as f_jieba: all_words_answer = 0 all_words_sample = 0 correct = 0 sentence1 = f_hmm.readline() sentence2 = f_jieba.readline() while sentence1: hmm_line = sentence1.split() jieab_line = set(sentence2.split()) same_list = [x for x in hmm_line if x in jieab_line] all_words_answer += len(hmm_line) all_words_sample += len(jieab_line) correct += len(same_list) sentence1 = f_hmm.readline() sentence2 = f_jieba.readline() recall = correct / all_words_answer precision = correct / all_words_sample f_mesure = (2 * precision * recall) / (precision + recall) print("词数:", all_words_answer) print("Precision:", round(precision, 4), "Recall", round(recall, 4), "F-mesure", round(f_mesure, 4)) if __name__ == "__main__": Process()
清华动物词典
自建筛选词典
stop_words文件
insect.txt文件
生成词典my_dict
-
你必须知道的495个C语言问题
2015-10-16 14:14:284.5 我有一个char*型指针碰巧指向一些int型变量,我想跳过它们。为什么((int*)p)++;这样的代码不行? 4.6 为什么不能对void*指针进行算术操作? 4.7 我有些解析外部结构的代码,但是它却崩溃了,显示出了... -
《你必须知道的495个C语言问题》
2010-03-20 16:41:184.5 我有一个char *型指针碰巧指向一些int型变量,我想跳过它们。为什么((int *)p)++; 这样的代码不行? 47 4.6 为什么不能对void *指针进行算术操作? 47 4.7 我有些解析外部结构的代码,但是它却崩溃了,显示... -
你必须知道的495个C语言问题(高清版)
2010-03-31 16:24:094.5 我有一个char *型指针碰巧指向一些int型变量,我想跳过它们。为什么((int *)p)++; 这样的代码不行? 47 4.6 为什么不能对void *指针进行算术操作? 47 4.7 我有些解析外部结构的代码,但是它却崩溃了,显示... -
mergeFolders.php for Mac
2020-03-09 12:34:48应用情景:在Windows系统下复制文件时,如果文件logo.jpg重复了,系统会在文件夹B里创建文件'logo(1).jpg',但是,Mac系统不会,只能"跳过","停止","替换",这个简单的要求"保留"为什么不做出来? 工具特性: ... -
Excel百宝箱9.0无限制破解版
2012-02-03 19:05:29【复制粘贴可见区】:复制与粘贴都跳过隐藏区域,仅对可见区生效 【批注管理器】:浏览批注、修改批注,以及对批注执行替换,包括精确匹配和模糊匹配 【带格式复制】:复制数据时可以将数据和格式信息一起复制过去,... -
Excel百宝箱
2012-10-27 17:09:21【复制粘贴可见区】:复制与粘贴都跳过隐藏区域,仅对可见区生效 【批注管理器】:浏览批注、修改批注,以及对批注执行替换,包括精确匹配和模糊匹配 【带格式复制】:复制数据时可以将数据和格式信息一起复制过去,... -
Foobar2000.AERO效果播放器
2015-03-13 14:59:54如果你下载的是完整的打包,你只需要阅读“配置文件使用说明”中的“图标的使用”和“字体的使用”部分就可以了,其他的都可以跳过。 如果你下载的是仅有配置文件的配置包,请完整阅读以下说明。 ====配置文件说明==... -
python cookbook(第3版)
2016-01-06 22:24:384.8 跳过可迭代对象的开始部分 4.9 排列组合的迭代 4.10 序列上索引值迭代 4.11 同时迭代多个序列 4.12 不同集合上元素的迭代 4.13 创建数据处理管道 4.14 展开嵌套的序列 4.15 顺序迭代合并后的排序迭代... -
Excel百宝箱9.0无限制破解版.rar
2012-09-05 09:31:51【复制粘贴可见区】:复制与粘贴都跳过隐藏区域,仅对可见区生效 【批注管理器】:浏览批注、修改批注,以及对批注执行替换,包括精确匹配和模糊匹配 【带格式复制】:复制数据时可以将数据和格式信息一起复制过去,... -
如何编写批处理文件批处理文件批处理文件
2010-04-14 10:36:10跳过空白行。您可通过指定可选 "options" 参数替代默认解析操作。这个带引号的字符串包括一个或多个 指定不同解析选项的关键字。这些关键字为: eol=c - 指一个行注释字符的结尾(就一个) skip=n - 指在文件开始时... -
3.5.3 给40亿个不重复的unsigned int的整数,没排过序的,然后再给几个数,如何快速判断这几个数是否在那40亿个数当中? 3.5.4 在一个文件中有10G个整数,乱序排列,要求找出中位数。内存限制为2G。 3.5.5 时分秒针...
-
Visual Studio程序员箴言--详细书签版
2012-10-16 20:37:39技巧3.2 在不打开“查找和替换”窗口的情况下,使用Ctrl+F3键搜索当前选中的单词 58 技巧3.3 不自动搜索当前选中的单词 58 3.1.3 重复上次搜索 59 技巧3.4 使用F3键搜索上次的搜索内容 59 3.2 快速搜索 59... -
入门学习Linux常用必会60个命令实例详解doc/txt
2011-06-09 00:08:45-n:防止sync系统调用,它用在用fsck修补根分区之后,以阻止内核用老版本的超级块覆盖修补过的超级块。 -w:并不是真正的重启或关机,只是写wtmp(/var/log/wtmp)纪录。 -f:没有调用shutdown,而强制关机或... -
iPhone开发秘籍(第2版)--源代码
2012-12-11 13:51:223.7.4 保留自动释放的对象 87 3.7.5 已保留属性 87 3.7.6 高保留计数 89 3.7.7 创建对象的其他方式 90 3.7.8 释放对象 91 3.8 创建单例 93 3.9 类别(扩展类) 93 3.10 协议 94 3.10.1 定义协议 95 3.10.2... -
adb1.0.26包含fastboot.exe
2019-03-05 15:11:03已经安装过的设备可以跳过此步。我使用的终端模拟器下载地址是:Terminal Emulator for Android Downloads 将 Android 设备与要运行 adb 的电脑连接到同一个局域网,比如连到同一个 WiFi。 打开 Android 设备上的... -
已经安装过的设备可以跳过此步。我使用的终端模拟器下载地址是:Terminal Emulator for Android Downloads 将 Android 设备与要运行 adb 的电脑连接到同一个局域网,比如连到同一个 WiFi。 打开 Android 设备上...
-
uboott移植实验手册及技术文档
2010-01-28 19:18:03在文件的最后加入Nand Flash的初始化函数,该函数在后面Nand Flash的操作都要用到。 u-boot运行到第2阶段会进入start_armboot()函数。其中nand_init()函数是对nand flash的最 初初始化函数。nand_init()函数在两个...