jeudi 27 juillet 2023

Cannot programmatically remove jpg using ::DeleteFile or "remove"

I cannot delete a jpg using Windows DeleteFile or remove. I can, however, delete other types of files in the same directory (txt, yaml). To make things even weirder, I can open a command prompt and remove the file using the "rm" command (I'm not opening the terminal window as an admin).
I am running Windows 11 and Visual Studio 2019 and yes, I am the owner of and do have full permissions on the file and no, the file is not opened first.

    int retVal = ::remove("C:\\Users\\melis\\Projects\\BartonNoProp.jpg");  //THIS FAILS
    retVal = ::remove("C:\\Users\\melis\\Projects\\Barton.jpg");  //THIS FAILS
    retVal = ::remove("C:\\Users\\melis\\Projects\\ss.yaml");  //THIS IS SUCCESSFUL

    BOOL result = ::MoveFileEx("C:\\Users\\melis\\Projects\\Barton.jpg", "C:\\Users\\melis\\Projects\\Train\\Barton.jpg", MOVEFILE_REPLACE_EXISTING);
    int rr = ::GetLastError();  //THIS SUCCEEDS IF THE SECOND FILE DOESN'T EXIST.  HOWEVER, IT FAILS IF THE SECOND FILE ALREADY EXISTS.

    result = ::DeleteFile("C:\\Users\\melis\\Projects\\ss2.yaml");
    rr = ::GetLastError();  // THIS IS SUCCESSFUL

    result = ::DeleteFile("C:\\Users\\melis\\Projects\\BartonNoProp.jpg");
    rr = ::GetLastError();  // THIS FAILS WITH CODE 5

Aucun commentaire:

Enregistrer un commentaire