Python中文
首页
教程
问答
标签
搜索
登录
注册
如何在比较两个目录时移动不同和不存在的文件?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有一个存档文件夹,名为“dir1”。<br/> 我有一个新的数据文件夹,名为“dir2”。<br/> 我有一个文件夹,名为“dir3”。<br/> 数据是jpgs,没有子文件夹。你知道吗</p> <pre><code>dir1 1.jpg 2.jpg 3.jpg 4.jpg dir2 1.jpg (edited file) 2.jpg (edited file) 3.jpg (same file as in dir1) 4.jpg (same file as in dir1) 5.jpg (new file) 6.jpg (new file) </code></pre> <p>我需要将新的、丢失的、编辑过的和不同的文件移到dir3。<br/> 结果是:</p> <pre><code>dir3 1.jpg 2.jpg 5.jpg 6.jpg </code></pre> <p>以下是我所拥有的:</p> <pre><code>from filecmp import dircmp dcmp = dircmp('dir1', 'dir2') def main(dcmp): for name in dcmp.diff_files, dcmp.right_only: print (name) if __name__ == "__main__": main(dcmp) </code></pre> <p>结果是:</p> <pre><code>['2.jpg', '1.JPG'] ['6.jpg', '5.jpg'] </code></pre> <p>如何将这些文件移到dir3而不是“print” 我试过“shutil”和“shutil”操作系统重命名“,但我不能让它工作。 <br/> <br/><br/> 来自“filecmp”和“dircmp”的信息。你知道吗</p> <pre><code>import filecmp filecmp.dircmp('dir1', 'dir2').report() </code></pre> <p>结果是:</p> <pre><code>diff dir1 dir2 Only in dir2 : ['5.jpg', '6.jpg'] Identical files : ['3.JPG', '4.JPG'] Differing files : ['1.JPG', '2.jpg'] </code></pre> <p>仅供参考。你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>以下是<a href="https://stackoverflow.com/a/8858026/3717717">answer</a>关于如何创建新目录并将文件移到其中的参考。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
Python中是否有类似Clojure的线程宏?
1 回答
Python中是否有类似JPanel的组件?
6 回答
Python中是否有类似MATLAB的vpasolve的等价解算器
7 回答
python中是否有类似NLTK的东西不需要安装?
4 回答
python中是否有类似osgi在java中试图解决的需求?
7 回答
python中是否有类似PAM的模块?
6 回答
Python中是否有类似Perl的Data::Dumper的工具用来检查数据结构?
6 回答
python中是否有类似robocy的函数,带有重试选项?
4 回答
Python中是否有类似Rstudio的帮助部分?
6 回答
python中是否有类似ruby的索引方法?
8 回答
python中是否有类似于“perlpe”选项的内容?
9 回答
Python中是否有类似于C++ STL映射的结构?
3 回答
python中是否有类似于C中预处理器行为的工具?
7 回答
Python中是否有类似于Harmony的let关键字的内容?
8 回答
python中是否有类似于matlab中fzero的函数?
10 回答
python中是否有类似于MATLAB中peaks(N)的函数/实现?
5 回答
Python中是否有类似于Matlab的deconvblind的函数?
7 回答
Python中是否有类似于Perl中“想要”的东西
7 回答
Python中是否有类似于Perl正则表达式中的"local"变量?
8 回答
python中是否有类似于php的$$变量的语法
3 回答