How to copy/replace a file into a folder in VB.NET?

后端 未结 2 952
生来不讨喜
生来不讨喜 2021-01-14 02:13

I used File.Copy(source, target, True), where source is a full path name, like c:\\source.txt and target is a folder, whi

2条回答
  •  孤独总比滥情好
    2021-01-14 02:18

    Target must contain a filename too:

    sSource = "C:\something.txt"
    sTarget = "C:\folder\something.txt"
    
    File.Copy(sSource, sTarget, True)
    

    If you want to programatically have the same filename just do:

    File.Copy(sSource, Path.Combine(sFolder, Path.GetFileName(sSource)), True)
    

    Read the MSDN Documentation to have examples and information about exceptions and use of the method.

提交回复
热议问题