Reputation: 7005
I have an odd issue copying files from one folder to another on the same drive.
If I copy to a particular folder PROBLEM_FOLDER the copying takes a very long time.
If I copy to another folder which I created as a test OK_FOLDER the copying is very fast.
I first noticed the problem after I accidentally completely filled my C DRIVE and had to remove a huge number of files from PROBLEM_FOLDER.
What could be the issue here?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace TestCopy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MoveFiles(@"C:\HOTDATA\DB\TEST", @"C:\PROBLEM_FOLDER\DB");
//MoveFiles(@"C:\HOTDATA\DB\TEST", @"C:\OK_FOLDER\DB");
}
public void MoveFiles(string sourceDir, string targetDir)
{
foreach(var file in Directory.GetFiles(sourceDir,"nEq*-1m*"))
{
string FileName = Path.GetFileName(file);
var targetPath = Path.Combine(targetDir, FileName);
if (File.Exists(targetPath))
{
//File.Delete(targetPath);
}
else
{
File.Move(file, targetPath);
}
}
}
}
}
Upvotes: 1
Views: 222
Reputation: 114
You might have hidden system files in that folder. Change your view settings to show hidden and untick the hide protected system files. In the old days c# was notoriously slow iterating folders and you have to do things a certain way to work with large folders. This was years ago though, so I don't know if it is still the case.
Upvotes: 1