TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

A tiny file comparison program written in Go

3 点作者 omerh超过 6 年前

3 条评论

dchest超过 6 年前
<p><pre><code> log.Print(&quot;Missing argument for files direcory, Exiting...&quot;) os.Exit(0) </code></pre> Exit code 0 is usually used for success. This is clearly an error.<p><pre><code> filePath + &quot;&#x2F;&quot; + file.Name() </code></pre> There&#x27;s path&#x2F;filepath module for cross-platform joining of file paths.<p>Don&#x27;t use defer f.Close() in the loop — defer will execute after the function returns. What you&#x27;re doing is opening all of the files in the directory and then closing them only when the program exists.<p><pre><code> if file.IsDir() == false { </code></pre> Already boolean, this should be<p><pre><code> if !file.IsDir() { </code></pre> Apart from all of this, it looks like the algorithm is very inefficient with all of those slice manipulations.
评论 #18644012 未加载
creatornator超过 6 年前
I made a similar utility a while back to help trim down my family photos library that had many duplicates [0]. I took the approach of a dry-run option and an option to go ahead and delete duplicate files too. It also traverses the folder recursively, to get all files in a tree.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;MatanSilver&#x2F;rmdupes" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;MatanSilver&#x2F;rmdupes</a>
omerh超过 6 年前
Did a complete refactor to do it more efficiently