dsp怪胎_IT怪胎:如何保持同名文件同步

dsp怪胎

dsp怪胎

image

You have most likely heard of services, such as Dropbox, which are used to keep files in sync across multiple machines. However, what if you want to perform this operation on a single machine? That is, keep files which have the same file name in sync across the machine such that when one of the files changes, they are all updated.

您最可能听说过服务,例如Dropbox,这些服务用于使文件在多台计算机上保持同步。 但是,如果要在一台计算机上执行此操作怎么办? 也就是说,在机器上保持具有相同文件名的文件同步,以便当其中一个文件更改时,它们都被更新。

This functionality can be quite useful, especially for developers or system administrators where duplication of files is sometimes required.

此功能非常有用,特别是对于有时需要复制文件的开发人员或系统管理员而言。

这个怎么运作 (How it Works)

Suppose you are a web developer who, over the course of time, has put together a nice collection of Javascript functions which you use throughout all the sites you maintain. As you add or improve upon this Javascript file (let’s call it “library.js”), only the current copy you are editing is updated. This would mean, for example, if you make a bug fix or improvement you would have to manually go apply it to each of your other sites’ source code folder as well.

假设您是一个Web开发人员,随着时间的推移,他已经整理了一组不错的Javascript函数,供您在所维护的所有站点中使用。 当您添加或改进此Javascript文件时(我们将其称为“ library.js”),仅更新您正在编辑的当前副本。 例如,这意味着,如果您进行错误修复或改进,则必须手动将其应用于其他站点的每个源代码文件夹。

Our tool attempts to solve the problem of having to manually go apply the updated file to each source folder. What it does:

我们的工具试图解决必须手动将更新的文件应用于每个源文件夹的问题。 它能做什么:

  1. Searches for all files with a specified name (library.js) within a specified root folder (%UserProfile%\Documents\Web Sites).

    在指定的根文件夹(%UserProfile%\ Documents \ Web Sites)中搜索具有指定名称(library.js)的所有文件。
  2. For all files named library.js, it locates the one which was modified most recently and notes its file hash value.

    对于所有名为library.js的文件,它将找到最近修改的文件,并记录其文件哈希值。
  3. All other files named library.js (which are not the most recent updated copy) then have their file hash value compared against the most recent (determined in the previous step).

    然后,将所有其他名为library.js的文件(不是最新更新的副本)的文件哈希值与最新文件(在上一步中确定)进行比较。
  4. If the file hash values are different, then the respective copy of library.js is replaced with the most recently updated copy.

    如果文件哈希值不同,则将library.js的相应副本替换为最近更新的副本。

Because we are using hash values to compare the files, we are assured that any files replaced are indeed different than the most recent copy. For instance, if you were to run the process and 5 file replacements were made, running the process again immediately afterwards would not make any replacements since the file hash values are now identical.

因为我们使用哈希值比较文件,所以可以确保替换的文件确实与最新副本不同。 例如,如果您要运行该进程并进行了5次文件替换,则此后立即再次运行该进程将不会进行任何替换,因为文件哈希值现在相同。

更新到最新复制工具 (Update to Newest Copy Tool)

The Update to Newest Copy Tool tool is a modified version of a batch script with the same name (both are available for download using the links at the bottom of the article) which has been converted to an EXE file in order to include the required Nirsoft HashMyFiles utility. The tool must be run from the command line with certain parameters specified. If you were to just run the EXE file by double-clicking, you will get a message indicating this.

“更新到最新副本工具”工具是具有相同名称的批处理脚本的修改版本(都可以使用文章底部的链接下载),该脚本已转换为EXE文件 ,以包括所需的Nirsoft HashMyFiles实用程序 。 该工具必须使用指定的某些参数从命令行运行。 如果您只是通过双击运行EXE文件,您将收到一条消息,指示您执行此操作。

To use Update to Newest Copy, you can view the parameters by running “UpdateToNewestCopy /?” which shows the following dialog:

要使用“更新到最新副本”,可以通过运行“ UpdateToNewestCopy /?”来查看参数。 显示以下对话框:

image

The only required parameters are the SourceFolder (e.g. %UserProfile%\Documents\Web Sites) and the FileName (library.js). However, you can alter the functionality by adding additional switches as described above.

唯一必需的参数是SourceFolder(例如%UserProfile%\ Documents \ Web Sites)和FileName(library.js)。 但是,您可以通过添加如上所述的其他开关来更改功能。

Examples

例子

The following command would find all files named “Common.vb” within the folder “C:\users\jfaulkner\documents\Code Files”, performing the replacement but making a backup of the current copy before overwriting (this output is what produced the top image for this article):

以下命令将在文件夹“ C:\ users \ jfaulkner \ documents \ Code Files”中找到所有名为“ Common.vb”的文件,执行替换操作,但在覆盖之前对当前副本进行备份(此输出是产生本文的顶部图片):

UpdateToNewestCopy “C:\users\jfaulkner\documents\Code Files” Common.vb /B

UpdateToNewestCopy“ C:\ users \ jfaulkner \ documents \ Code文件” Common.vb / B

The following command performs the same search action as above, however it only reports on files which would be replaced and does not actually perform any file operations:

以下命令执行与上述相同的搜索操作,但是它仅报告将被替换的文件,而实际上不执行任何文件操作:

UpdateToNewestCopy “C:\users\jfaulkner\documents\Code Files” Common.vb /V

UpdateToNewestCopy“ C:\ users \ jfaulkner \ documents \ Code文件” Common.vb / V

Assume there is a file named “C:\Config\FilesToSearch.txt” with the following contents:

假设有一个名为“ C:\ Config \ FilesToSearch.txt”的文件,其内容如下:

library.js Common.vb

library.js Common.vb

The following command would search the my documents folder of the current user and report on any updates to “library.js” and “Common.vb”, but would not actually perform any update operations:

以下命令将搜索当前用户的“我的文档”文件夹,并报告对“ library.js”和“ Common.vb”的任何更新,但实际上不会执行任何更新操作:

UpdateToNewestCopy “%UserProfile%\Documents” “C:\Config\FilesToSearch.txt” /L /V

UpdateToNewestCopy“%UserProfile%\ Documents”“ C:\ Config \ FilesToSearch.txt” / L / V

流程自动化 (Automating the Process)

This process is an ideal candidate for automation. By creating a scheduled task (nothing special required) with the specified settings and having it run daily/hourly/every 15 minutes (depending on your requirements), you can keep files sync’ed in true set-it-and-forget-it fashion.

此过程是自动化的理想选择。 通过使用指定的设置创建计划任务 (不需要任何特殊操作)并使其每天/每小时/每15分钟运行一次(取决于您的要求),您可以使文件保持真正的“设置后忘记”状态时尚。

下载 (Download)

Update to Newest Copy – modified executable format

更新为最新副本–修改后的可执行格式

Update to Newest Copy – source batch files (more command line oriented)

更新到最新副本–源批处理文件 (更多面向命令行)

翻译自: https://www.howtogeek.com/163824/it-geek-how-to-keep-files-with-the-same-name-in-sync/

dsp怪胎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值