大目录/子目录数据传输
本文关键字:子目录 数据传输 | 更新日期: 2023-09-27 18:26:58
我正试图编写一个脚本来遍历一个大目录并递归地复制文件,但目的地一次只能接受2个gig的信息。有没有办法把转移分成小于2个零工部分?我可以写一个简单的脚本在主目录上复制,但问题是Destination不能同时接受那些大的传输。我想用一个主函数来创建子函数,以在较小的段或会话中传输数据,但我不太确定如何做到这一点。像这样的东西,但分成了几个部分。
$SPOnlineDir = "Our sharepoint online library address"
$MainStore = @("''server'Dir1", "''server'Dir2", "''server'Dir3")
function Copy-ToSPO()
{
Foreach($StoreInst in $MainStore)
{
Copy-Item -LiteralPath $StoreInst -Destination $SPOnlineDir -Force
}
}
Copy-ToSPO
找到了一个带有少量C#的解决方案:
命名空间控制台应用程序2{班级计划{static void Main(string[]args){var Source=GetSourceDirectory();var Destination=GetDestinationDirectory();
CopyDirectory(Source, Destination);
Console.WriteLine("'n'nFinished.");
Console.ReadKey(true);
}
static DirectoryInfo GetSourceDirectory()
{
var verifyPath = false;
var pathExists = false;
var path = "";
while(!verifyPath)
{
while(!pathExists)
{
Console.WriteLine("Please enter the Source Directory path.");
path = Console.ReadLine();
Console.WriteLine("Verifying directory exists...");
pathExists = Directory.Exists(path);
if (!pathExists)
Console.WriteLine("That path does not exist.");
}
Console.WriteLine("Directory found.");
Console.WriteLine("Please verify the source file path (Y or N):");
Console.WriteLine(path);
verifyPath = GetVerification();
}
return new DirectoryInfo(path);
}
static DirectoryInfo GetDestinationDirectory()
{
var verifyPath = false;
var path = "";
while (!verifyPath)
{
var pathExists = false;
var createDir = false;
while (!pathExists)
{
Console.WriteLine("Please enter the Destination Directory path.");
path = Console.ReadLine();
Console.WriteLine("Verifying directory exists...");
pathExists = Directory.Exists(path);
if (!pathExists)
{
Console.WriteLine("Directory does not exist. Would you like to create it?");
createDir = GetVerification();
pathExists = createDir;
}
else
Console.WriteLine("Directory found.");
}
Console.WriteLine("Please verify the source file path (Y or N):");
Console.WriteLine(path);
verifyPath = GetVerification();
if (verifyPath && createDir)
Directory.CreateDirectory(path);
}
return new DirectoryInfo(path);
}
static bool GetVerification()
{
char[] VerificationChoices = { 'y', 'Y', 'n', 'N' };
var VerifiedChar = Console.ReadKey().KeyChar;
while (!VerificationChoices.Contains(VerifiedChar))
VerifiedChar = Console.ReadKey().KeyChar;
Console.Write("'n'n");
return VerifiedChar == 'Y' || VerifiedChar == 'y';
}
static void CopyDirectory(DirectoryInfo DirectoryToCopy, DirectoryInfo Destination)
{
foreach(var SubFolder in DirectoryToCopy.GetDirectories())
{
var SubDestination = Destination.CreateSubdirectory(SubFolder.Name);
Console.WriteLine("Creating Directory: " + SubDestination.FullName);
CopyDirectory(SubFolder, SubDestination);
}
foreach(var File in DirectoryToCopy.GetFiles())
{
var FullDestinationPath = Destination.FullName + "''" + File.Name + File.Extension;
File.CopyTo(FullDestinationPath);
Console.WriteLine("Creating File: " + FullDestinationPath);
}
}
}
}
感谢您的投入。