简体   繁体   中英

Cut & paste of file : C#

在C#中,最简单的方法是,如果我在VS Windows Forms应用程序中单击按钮,则将自己(exe程序)从c:\\data剪切并粘贴到c:\\data2吗?

There is no way an executing application can move itself.

What you could do is:

Suppose you have:

  • A - Executing Application.
  • B - Spawned Application.

Now:

  1. A is executing.
  2. A creates another app called B .
  3. A shuts down.
  4. B moves A from Data to Data2 .
  5. B starts A from new location.
  6. B shuts down.

You can File.Copy to transfer the file from one folder to another. For example...

File.Copy("C:\Data\MyProgram.exe", "C:\Data2\MyProgram.exe"

Taz suggested that the file won't copy as it's executing and that's something to watch out for, but I've been able to copy running programs before.

There is no way. I don't think it is possible as the file is executing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM