MrTV
asked on
C# copy file and recopy again
the code below i try to copy form songs from sorce to destination foder such as if sorce folder have 10 song and destination folder have 35 song I want to copy form source folder 35 song by recopy from begining song again until 35 song
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.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
sorrceTextbox.Text = dlg.SelectedPath;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg2 = new FolderBrowserDialog();
if (dlg2.ShowDialog() == DialogResult.OK)
{
destTextbox.Text = dlg2.SelectedPath;
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void startcopy_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(sorrceTextbox.Text) || String.IsNullOrEmpty(destTextbox.Text))
{
this.labelStart.Text = "Hello World";
}
else
{
int fileCount = Directory.GetFiles(destTextbox.Text).Length;
this.labelStart.Text = fileCount.ToString() ;
CopyFiles(sorrceTextbox.Text, destTextbox.Text);
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void CopyFiles(string sourceDir, string targetDir)
{
string[] sourceFiles = Directory.GetFiles(sourceDir);
for (int i = 0; i < sourceFiles.Length; i++)
{
string sourceFile = sourceFiles[i];
string targetFile = targetDir + "\\" + "1" + (i + 10).ToString().PadLeft(3, '0') + "1" + ".mp3";
File.Copy(sourceFile, targetFile, true);
}
}
}
}
ASKER
hi Pryrates
source Folder 1 has 10 files.
target Folder 2 has 35 files.
total is 60 folder will recopy until 35
it like a festival that have a song that compose for this festival and it mix with popular song but song that compose for festival will play many time
source Folder 1 has 10 files.
target Folder 2 has 35 files.
total is 60 folder will recopy until 35
it like a festival that have a song that compose for this festival and it mix with popular song but song that compose for festival will play many time
what do you mean by "recopy until 35" ?
In your destination folder you have 35 files / items.
In your source folder you have 10 files / items.
You want in your destination folder to be as many copies of your source folder files as items are in your destination folder originally?
what to do:
a.) 35 destination, 10 in source => copy 10 files 35 times in your destination folder?
b.) 35 destination, 10 in source => 70 files should be in destination afterwards. 2 times all from source and 1st 5 from source to reach 35 copies.
Or did I still not get it?
In your destination folder you have 35 files / items.
In your source folder you have 10 files / items.
You want in your destination folder to be as many copies of your source folder files as items are in your destination folder originally?
what to do:
a.) 35 destination, 10 in source => copy 10 files 35 times in your destination folder?
b.) 35 destination, 10 in source => 70 files should be in destination afterwards. 2 times all from source and 1st 5 from source to reach 35 copies.
Or did I still not get it?
ASKER
Hi Pryrates
if destination have 80 and source have 10 the total in destination is 160 toal
if the destination is 120 total will be 240
it mean that sorce file will copy 1,2,3 ... 10 then 1 ,2 ... 10 .1,2 ..10 antil sorce destination was copy 120 file but change the name
if destination have 80 and source have 10 the total in destination is 160 toal
if the destination is 120 total will be 240
it mean that sorce file will copy 1,2,3 ... 10 then 1 ,2 ... 10 .1,2 ..10 antil sorce destination was copy 120 file but change the name
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you
you are welcome
Can you be more specific?
Do you want to sync the content of two folders?
Folder 1 has 10 files.
Folder 2 has 35 files.
After copy Folder 1 and 2 both have 45 files?
Or just folder 2 should contain 45 files after copy?