c#/기타

[c#] File Copy, Delete, Move

byH 2022. 1. 21. 08:06
728x90
반응형

1. File Copy

  private void Form1_Load(object sender, EventArgs e)
        {


            string ori_File = @"C:\copytest\test_ori.txt";
            string new_file = @"C:\copytest\test_new.txt";
            System.IO.File.Copy(ori_File, new_file);
           
        }

 

2. File Delete 

    private void Form1_Load(object sender, EventArgs e)
        {


            string ori_File = @"C:\copytest\test_ori.txt";
            string new_file = @"C:\copytest\test_new.txt";
            //System.IO.File.Copy(ori_File, new_file);
            System.IO.File.Delete(new_file);
        }

 

3. File Move

기존에 test_ori.txt 파일은 C:\copytest\test_ori.txt 경로에 있고 ,

movetest 폴더는 비어있다. 

 private void Form1_Load(object sender, EventArgs e)
        {


            string ori_File = @"C:\copytest\test_ori.txt";
            string new_file = @"C:\copytest\movetest\test_ori.txt";
            //System.IO.File.Copy(ori_File, new_file);
            System.IO.File.Move(ori_File,new_file);
        }

test_ori.txt 파일이 movetest 폴더로 이동된다.

728x90
반응형