0

On Windows, creating file filename.htm sometimes create an associated folder filename.files at the same time if needed. If we delete filename.htm, the associated folder is deleted at the same time.

According to this, it is a behavior of Windows Explorer. It is called 'Connected Files'. This discuss SHFileOperation.

Can I mimic the behavior by Python? Python os.remove() or win32api.DeleteFile() won't do the same thing.

I am worried that brutally deleting both the file and folder confuses Windows Explorer. Or leave some something trashy in the registry?

minion
  • 561
  • 4
  • 17
  • 1
    windows will not create subfolders when you creating a .htm file. that's something your BROWSER does when you save the page, and select "html - complete" (or whatever your browser's equivalent is). – Marc B Oct 05 '16 at 16:10
  • Yes, I know. So I said 'if needed.' Anyway, it is not the core of the question. I modified the question. – minion Oct 05 '16 at 16:12
  • and like you said, it's behavior of Explorer. if you invoke explorer api calls to delete the .htm file, it'll likely delete the `_files` folder as well, but if you go low-level and use (say) a normal `unlink()` on the html file, then the _files folder is *NOT* touched, because Explorer was not involved at all. – Marc B Oct 05 '16 at 16:15
  • Is it safe to go low level? Microsoft Word once told me that 'this file name is occupied please select another name.' although the file does being deleted. – minion Oct 05 '16 at 16:27
  • googling "SHFileOperation python" indicates there may be a pywin32 module with win32com.shell.SHFileOperation. Also ActiveState Python has the same with a sourceforge link to source. – Kenny Ostrom Oct 05 '16 at 20:43

0 Answers0