简体   繁体   English

Powershell 或 C#:使用 csv 数据将文件从一个位置复制到另一个位置

[英]Powershell or C#: Copy files from one location to another using csv data

I have a csv with 2 columns.我有一个有 2 列的 csv。 1st column is the path and filename of the file I want to copy.第一列是我要复制的文件的路径和文件名。 The second column is the destination path.第二列是目标路径。

I'd like to create a script that parses the csv and copies the files in something like a foreach loop in C#, but I'm thinking Powershell may be the easiest and most efficient way to accomplish this.我想创建一个脚本来解析 csv 并将文件复制到 C# 中的 foreach 循环中,但我认为 Powershell 可能是完成此任务的最简单和最有效的方法。

Should I load the csv in a C# script, then create a foreach loop that loads the origin and destination and then completes the copy, or would a simple one-liner in Powershell be able to do this quicker?我应该在 C# 脚本中加载 csv,然后创建一个 foreach 循环来加载起点和终点,然后完成复制,还是 Z531B84AD41B2A753DA83ACF367990701 中的简单单行能够更快地完成此操作?

Part of the answer here: https://social.technet.microsoft.com/Forums/office/en-US/aa20cabb-3196-472d-9594-aaa0ec10fa03/powershell-read-csv-file-line-by-line-and-only-first-header?forum=winserverpowershell部分答案在这里: https://social.technet.microsoft.com/Forums/office/en-US/aa20cabb-3196-472d-9594-aaa0ec10fa03/powershell-read-csv-file-line-by-line- and-only-first-header?forum=winserverpowershell

I would use the powershell if your csv file had headers cause it would be quite easy.如果您的 csv 文件有标题,我会使用 powershell 因为它会很容易。 But C# if not or if you want some harder process (check if file exists before copying or else)但是 C# 如果不是或者如果你想要一些更难的过程(在复制之前检查文件是否存在)

Powershell will be way easier than to handle this compared to c#.与 c# 相比,Powershell 比处理这个要容易得多。 C# will be faster especially if you need to work with threads. C# 会更快,尤其是在您需要使用线程时。

So at the ends, it depends on your requirements.所以最后,这取决于你的要求。 I would recommend powershell for the beginning if you dont need to handle enormous amount of data.如果您不需要处理大量数据,我会推荐 powershell 一开始。

But if youre very familiar with c#, feel free to do it in c# as well但是,如果您对 c# 非常熟悉,也可以在 c# 中进行操作

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

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