This is some basic things you can do with the WinAPI class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | static void FO_WinApi(Args _args) { str root = "C:"; str path = "C:\\temp"; str fileName = "Test.pdf"; str fileName2 = "Test2.pdf"; str file = path + "\\" + fileName; str file2 = path + "\\" + fileName2; int x, y; ; // Does folder exist? print WinAPI::folderExists(path); // Does file exist? print WinAPI::fileExists(file); // Copy file. print WinAPI::copyFile(file,file2); // New file exists? print WinAPI::fileExists(file2); // Delete new file. print WinAPI::deleteFile(file2); // New file still there? print WinAPI::fileExists(file2); // Get current cursor position. [x, y] = WinAPI::getCursorPos(); print x; print y; // Get time and date format. print WinAPI::getSystemLocaleDateStr(); print WinAPI::getSystemLocaleTimeStr(); // Gets current computer name. print WinAPI::getComputerName(); // Gets total disk space. print int2str(WinAPI::getDiskTotalSpaceInKb(root) / 1000) + " MB"; // Gets current free space on disk. print int2str(WinAPI::getDiskFreeSpaceInKb(root) / 1000) + " MB"; // Date when file was last accessed. print WinAPI::getFileAccessedDate(file); // Time when file was last accessed(In seconds). print WinAPI::getFileAccessedTime(file); // Gets path to temp directory. print WinAPI::getTempPath(); // Gets a generated temporary filename, prefix "FO_". print WinAPI::getTempFilename(path, "FO_"); pause; } |
With this class you can get just about all the information you need about your system. Many methods have a tendency to return containers with various information, this means that you need to know how to handle containers to access the information you want.
Last 5 posts in Development
- No valid document identified from the entity key - April 9th, 2010
- Using Regular Expressions in Dynamics AX - October 2nd, 2009
- Create class and methods in x++ - December 22nd, 2008
- Simple field lookup in form - October 13th, 2008
- Get your Intercompany CustAccount - September 29th, 2008
I am trying to delete file with help of WinAPI class function named deleteFile(_fileName) but it is not deleting the file.
it still exist there.
Well I would need more information to say anything with certainty, but there are some possible reasons why you can’t delete the file:
1. The file is on your local computer but Dynamics AX is trying to delete the file on the computer the AOS is located on. You can use the methods fileExists and folderExists to make sure that you can locate the file before you try to delete it.
2. Dynamics AX might only have read rights on the file you are trying to delete. You can set that up in the folder properties.