0

フォルダーからファイルをコピーして、作成した別のフォルダーに貼り付けようとしています

以下のコードでフォルダーを作成済みです。

DirectoryInfo di = Directory.CreateDirectory(path);

path は、フォルダーが作成される場所のパスです。

このフォルダを別のフォルダのファイルで埋めるにはどうすればよいですか pls.

ありがとう

4

2 に答える 2

1

これにより、必要なものが得られます。

http://msdn.microsoft.com/en-us/library/cc148994.aspx

于 2013-05-26T16:48:19.167 に答える
0

これにより、指定された検索パラメーターを持つファイルが検索され、コピーされます。

public static void findAndCopy(string _sourcePath, string _destPath, string _searchParam )
{

    if (System.IO.Directory.Exists(_sourcePath))
    {
        string[] files = System.IO.Directory.GetFiles(_sourcePath, _searchParam, System.IO.SearchOption.AllDirectories);
        string destFile = "";
        string fileName = "";

        // Copy the files  
        foreach (string s in files)
        {
            // Use static Path methods to extract only the file name from the path.
            fileName = System.IO.Path.GetFileName(s);
            destFile = System.IO.Path.Combine(_destPath, fileName);
            try
            {
                System.IO.File.Copy(s, destFile, false);
            }
            catch (UnauthorizedAccessException uae)
            {
                log.Warn(uae);
            }
            catch (IOException ioe)
            {
                log.Warn(ioe);
            }
        }
    }
    else
    {
        log.Error("Source path not found! " + _sourcePath);
    }
}//end findAndCopy
于 2013-11-15T15:16:41.187 に答える