I'm trying to move a large number of files. I get the path of source and destination from database.
It takes hours to move images, and I was wondering if there is a faster way for moving large numbers of files.
Table example:
source | destination |
---|---|
C:\x | D:\y |
C:\z | D:\y |
This the code I'm using.
var datasource = @"00.000.0.00";
var database = "maydatabase";
var username = "power";
var password = "123";
string connString = @"Data Source=" + datasource + ";Initial Catalog="
+ database + ";Persist Security Info=True;User ID=" + username + ";Password=" + password;
SqlConnection conn = new SqlConnection(connString);
static void moveImg(string getimg, SqlConnection conn)
{
using (SqlCommand command = new SqlCommand(getimg, conn))
{
command.CommandTimeout = 0;
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
if ((File.Exists(reader["source"].ToString())) && !(File.Exists(reader["destination"].ToString())))
{
File.Move(reader["source"].ToString(), reader["destination"].ToString(), true);
}
}
}
}
}
Note
The number of rows in database can exceed 1 million, meaning 1 million images to move. Each image has size between 16KB and 60KB.
The query takes 1.30 mins to run. I don't know how can I get the timing for how long a file move takes, as not every file is same size. I can tell from the log file that it moves around 4 to 6 files in 1 second.