Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# copy file to directory

string fileToCopy = "c:myFoldermyFile.txt";
string destinationDirectory = "c:myDestinationFolder";

File.Copy(fileToCopy, destinationDirectory + Path.GetFileName(fileToCopy));
Comment

c# copy file to system folder

change permation:
<requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
Comment

c# copy files from one folder to another

// Simple synchronous file copy operations with no user interface.
// To run this sample, first create the following directories and files:
// C:UsersPublicTestFolder
// C:UsersPublicTestFolder	est.txt
// C:UsersPublicTestFolderSubDir	est.txt
public class SimpleFileCopy
{
    static void Main()
    {
        string fileName = "test.txt";
        string sourcePath = @"C:UsersPublicTestFolder";
        string targetPath =  @"C:UsersPublicTestFolderSubDir";

        // Use Path class to manipulate file and directory paths.
        string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
        string destFile = System.IO.Path.Combine(targetPath, fileName);

        // To copy a folder's contents to a new location:
        // Create a new target folder.
        // If the directory already exists, this method does not create a new directory.
        System.IO.Directory.CreateDirectory(targetPath);

        // To copy a file to another location and
        // overwrite the destination file if it already exists.
        System.IO.File.Copy(sourceFile, destFile, true);

        // To copy all the files in one directory to another directory.
        // Get the files in the source folder. (To recursively iterate through
        // all subfolders under the current directory, see
        // "How to: Iterate Through a Directory Tree.")
        // Note: Check for target path was performed previously
        //       in this code example.
        if (System.IO.Directory.Exists(sourcePath))
        {
            string[] files = System.IO.Directory.GetFiles(sourcePath);

            // Copy the files and overwrite destination files if they already exist.
            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(targetPath, fileName);
                System.IO.File.Copy(s, destFile, true);
            }
        }
        else
        {
            Console.WriteLine("Source path does not exist!");
        }

        // Keep console window open in debug mode.
        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# for each textbox lines 
Csharp :: Character Controller unity isGrounded is false 
Csharp :: check connection c# 
Csharp :: how to get the current gameobject animator in unity 
Csharp :: how to change image color unity 
Csharp :: string to int c# unity 
Csharp :: check if process is open c# 
Csharp :: how to set the fps in monogame 
Csharp :: unity enable gameobject 
Csharp :: c# get free space on drive 
Csharp :: urlreferrer in asp.net core 
Csharp :: c# boilerplate 
Csharp :: detecting a right click unity 
Csharp :: unity change sprite source image 
Csharp :: decode base64 string c# 
Csharp :: newline in button wpf 
Csharp :: windows form rounded corners 
Csharp :: c# count number of occurrences in string 
Csharp :: get random point in collider unity 
Csharp :: how to edit Camera.size property unity 
Csharp :: c# monogame mouse position 
Csharp :: itextsharp landscape a4 
Csharp :: There is already a virtual axis named Horizontal registered. unity 
Csharp :: Add float value to ui text in unity 
Csharp :: base64decode C# 
Csharp :: read configuration workerservice 
Csharp :: how check if variable is send to page or not in laravwel 
Csharp :: how to cast list to observablecollection c# 
Csharp :: unity list to array 
Csharp :: c# datetime iso 8601 format 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =