I’m trying to use toolkit to delete .drw files under working directory. There is a situation when the model mounted to the drawing is missing, I can’t manage to delete the drw file with promdlnameretrieve() and Promdldelete(). Does anyone know any other method to delete a file from disk in toolkit, many thanks.
Solved! Go to Solution.
either use pro/toolkit function to get a ProArray of all files in a directory and extract entries matching name and/or extension from ProArray
ProFilesList(...)
or use
#include <filesystem>
std::filesystem::directory_iterator
something like this (verify spelling and function names with cpp reference):
std::filesystem::path p{"directory_in_question"};
std::wstring base_name{"drawing_name_in_question"};
std::vector<std::filesystem::path> delete_me;
for (auto const& dir_entry : std::filesystem::directory_iterator{p}){
if( dir_entry.path().stem().extension().wstring().find(L"drw") == std::wstring::npos){
continue;
}
if( dir_entry.path().stem().stem().wstring() != base_name)
continue;
delete_me.push_back(dir_entry.path());
// or std::filesystem::remove( dir_entry.path())
}
std::for_each(delete_me.begin(), delete_me.end(),
[](auto &p) { std::error_code ec; std::filesystem::remove(p, ec); });
More details are: there is a C.drw drawing, the model mounted to the drawing is C.prt. For some reason the C.prt is missing, now I try to use toolkit to delete C.drw, it doesn’t work.
Is there a particular reason why the delete must be done with the toolkit API? Could you just use built in C functions to delete the file(s)?
That would be my last option, also I’m not sure if it works for the version postfix , I think I will try it at last, before that I wonder if there is another option.
You must check the origin of the model before deleting. This must match with your current working dir.
Yes, but it’s just the origin model is missing or renamed to another name, now I can’t load and display the drw file, so I’m trying to delete it.
Ithink, you got an error in promdlnameretrieve(), because a model is not found.
You can open a drawing in simplified representation. I do not remember exactly type of the representation. In this representation all drawing views is only bounding rectangles. Linked model will not loaded in to session. But need to turn on old style representations (in config.pro).
HI, thanks for the info.
i didn't know i can do that with a drawing like that, will try later, thanks.
HIH
yes, it is an option.
just wonder if i can delete the outdated drawing file directly.
Many people were suggesting using out of the box C or C++ functionality already...
Is there anything preventing using any of the following?
std::remove(...)
std::filesystem::remove(...)
_wunlink(...)
_unlink(...)
DeleteFile(...)
Hi, sir. I don’t know how to do with the version numbers, as in *.drw.3. I wouldn’t know the version number beforehand. Even I can have the path of the file, the path would end with.drw, not.3 or.5. Honestly I don’t know what to do here.
either use pro/toolkit function to get a ProArray of all files in a directory and extract entries matching name and/or extension from ProArray
ProFilesList(...)
or use
#include <filesystem>
std::filesystem::directory_iterator
something like this (verify spelling and function names with cpp reference):
std::filesystem::path p{"directory_in_question"};
std::wstring base_name{"drawing_name_in_question"};
std::vector<std::filesystem::path> delete_me;
for (auto const& dir_entry : std::filesystem::directory_iterator{p}){
if( dir_entry.path().stem().extension().wstring().find(L"drw") == std::wstring::npos){
continue;
}
if( dir_entry.path().stem().stem().wstring() != base_name)
continue;
delete_me.push_back(dir_entry.path());
// or std::filesystem::remove( dir_entry.path())
}
std::for_each(delete_me.begin(), delete_me.end(),
[](auto &p) { std::error_code ec; std::filesystem::remove(p, ec); });