Jump to content

Klasör Kopyalama


korasoglu
 Share

Recommended Posts

Arkadaşlar seçilen klasörü istenilen konuma nasıl kopyalayabilirim.

folderBrowserDialog1.ShowNewFolderButton = true;
            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                
                string source = folderBrowserDialog1.SelectedPath;
                string target = Application.StartupPath + @"\Kategori\" + combo.Text + "\\";
                Directory.Move(source, target);
            }
burada hata nerede anlamadım ama halen var olan bir dosya oluşturulamaz diye hata veriyor.
 
Edit :
 
string source = folderBrowserDialog1.SelectedPath;
                string target = Application.StartupPath + "\\Kategori\\" + combo.Text;
                Directory.Move(folderBrowserDialog1.SelectedPath, target + "//deneme");
 
bu şekilde isim değiştirerek taşıdı ama benim istediğim kopyalanmasıydı.
Edited by korasoglu
Link to comment
Share on other sites

  • Editor
private void copyDirectory(string strSource, string strDestination)
{
    if (!Directory.Exists(strDestination))
    {
        Directory.CreateDirectory(strDestination);
    }

    DirectoryInfo dirInfo = new DirectoryInfo(strSource);
    FileInfo[] files = dirInfo.GetFiles();
    foreach(FileInfo tempfile in files )
    {
        tempfile.CopyTo(Path.Combine(strDestination,tempfile.Name));
    }

    DirectoryInfo[] directories = dirInfo.GetDirectories();
    foreach(DirectoryInfo tempdir in directories)
    {
        copyDirectory(Path.Combine(strSource, tempdir.Name), Path.Combine(strDestination, tempdir.Name));
    }

}

Bu methodu yapıştırın daha sonra nerede kopyalatmak istiyorsanız oraya

 

copyDirectory(kaynak klasör,hedef klasör);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...