Application.FileManager.CopyFile or System.IO.File.Copy?

Application.FileManager.CopyFile or System.IO.File.Copy?

Skadborg.NTI
Advocate Advocate
564 Views
1 Reply
Message 1 of 2

Application.FileManager.CopyFile or System.IO.File.Copy?

Skadborg.NTI
Advocate
Advocate

I only see two differences between Application.FileManager.CopyFile or System.IO.File.Copy - am I missing some?

 

1: System.IO.File.Copy handles any filetype, Application.FileManager.CopyFile handles only Inventor filetypes.

2: Application.FileManager.CopyFile has three different overwrite levels (kOverwriteExistingFile, kOverwriteReadOnlyFile and kOverwriteReservedFile). System.IO.File.Copy only has Overwrite true/false and can not overwrite a ReadOnly protected file.

 

565 Views
1 Reply
Reply (1)
Message 2 of 2

Dev_rim
Advocate
Advocate

Hi,

I always choice System.IO library. When designing anything for inventor I think it is important to leave application object to itself as much as possible. Also at some projects I am using external files to collect data like XML, Excel files, or images and icons etc.. So my project folders also can contain "non-Inventor" files. At the end its always better to use original Windows libraries.

 

If you want to overwrite read-only protected files, you can change the ReadOnly attribute of the file like one line of code 🙂 

File.SetAttributes("C:\\myfile.txt", File.GetAttributes("C:\\myfile.txt") & ~FileAttributes.ReadOnly);

 

More detailed one:

var attr = File.GetAttributes(path);

// set read-only
attr = attr | FileAttributes.ReadOnly;
File.SetAttributes(path, attr);

// unset read-only
attr = attr & ~FileAttributes.ReadOnly;
File.SetAttributes(path, attr);

 

At the end I think it's your choice, it depends what kind of projects you are working on, and your style for sure.

For me, if I can do anything using original Windows libraries, I prefer doing them using original Windows libraries.

 

Regards

Devrim

If my answer is solved your problem, please mark it as Solution

Freundliche Grüße / Kind Regards