简体   繁体   English

如何创建一个脚本,允许使用路径列表作为在 PowerShell in.bat 脚本中复制文件的参考

[英]how to create a script that allows to use the path list as a reference for copying files in PowerShell in .bat script

I'm looking for a way to automate archiving where after I plug my two external drives I can copy all my resources.我正在寻找一种自动归档的方法,在插入两个外部驱动器后,我可以复制所有资源。 The problem is that I have different file structures on my laptop and on both external drives so I need to select specific folders to be copied.问题是我的笔记本电脑和两个外部驱动器上的文件结构不同,因此我需要复制 select 个特定文件夹。 It means that I can't select one root folder and copy it straightforward.这意味着我不能 select 一个根文件夹并直接复制它。 I tried to find a way to declare more than one path in the cp command and in the copy command, without success.我试图找到一种在cp命令和copy命令中声明多个路径的方法,但没有成功。 An example path:示例路径:

/my_programming_stuff /my_programming_stuff

              /folder1
              /folder2
              /folder3
              /folder4

I want to select only the first 3 folders to copy them into external drive1 and external drive 2 .我只想将 select 的前 3 个文件夹复制到外部驱动器 1 和外部驱动器 2中。 The idea is to create a .bat file that will copy everything at once ( in the best case scenario it will be copied simultaneously on both external drives, so it will be much faster).这个想法是创建一个.bat文件,它会立即复制所有内容(在最好的情况下,它会同时复制到两个外部驱动器上,因此速度会快得多)。 Another problem is that there needs to be a bypass the ntfs long path limitations (max. 260 characters).另一个问题是需要绕过 ntfs 长路径限制(最多 260 个字符)。 Flags that I want to use:我想使用的标志:

  • Copy the files and directories and all of their attributes, including ownerships and permissions.复制文件和目录及其所有属性,包括所有权和权限。
  • Recursively copy directories and their contents.递归复制目录及其内容。
  • When copying files from one directory to another, only copy files that either doesn't exist or are newer than the existing corresponding files, in the destination directory.将文件从一个目录复制到另一个目录时,只复制目标目录中不存在或比现有相应文件更新的文件。
  • data verification (so it's certain that the copy was verified)数据验证(因此可以肯定副本已被验证)
  • progression bar with time eta带有时间 eta 的进度条

Until now I was using Total Commander to do this but every day I need to pick only a few folders to be copied which takes time and is inefficient.到目前为止,我一直在使用 Total Commander 来执行此操作,但每天我只需要选择几个文件夹进行复制,这既费时又效率低下。

I have experience with Bash and PowerShell but I am not sure how to handle this topic.我有 Bash 和 PowerShell 的经验,但我不确定如何处理这个话题。

Create a static batch file with robocopy commands.使用 robocopy 命令创建一个 static 批处理文件。 I think /copyall is the only switch you need to specify for all this.我认为 /copyall 是您需要为此指定的唯一开关。 Other defaults should satisfy requirements.其他默认值应满足要求。

https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy

I think your time will be better spent learning how to use either FastCopy or FreeFileSynce .我认为您最好将时间花在学习如何使用FastCopyFreeFileSynce 上 I used FreeFileSync some years ago but got disgusted with the it's constantly changing format of its xml file used for starting a backup, so I switched to FastCopy.几年前我使用过 FreeFileSync,但对它不断改变用于启动备份的 xml 文件的格式感到厌恶,所以我切换到 FastCopy。 But it looks like FreeFileSync may be getting their act together and I aim to do some experiments over the summer to see if I want to switch back to it.但看起来 FreeFileSync 可能正在采取行动,我打算在夏天做一些实验,看看我是否想切换回它。

Both can handle the long filename format issues, both can be executed by a batch file, both seem to have a lot of quality, but FreeFileSync has more features - and more bloated because of the features.两者都可以处理长文件名格式问题,都可以通过批处理文件执行,两者似乎都有很多质量,但 FreeFileSync 具有更多功能 - 并且由于这些功能而更加臃肿。 But speed wise, I think FastCopy is probably one of the better products out there and very streamline in use and design.但就速度而言,我认为 FastCopy 可能是目前最好的产品之一,并且在使用和设计方面非常精简。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM