os.unlink() AND win32api.DeleteFile()

R

rbt

Can someone detail the differences between these two? On Windows which
is preferred?

Also, is it true that win32api.DeleteFile() can remove the 'special'
files located in the 'special' folders only accessible by the shell
object such as Temporary Internet Files, etc.

Thanks!
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

rbt said:
Can someone detail the differences between these two? On Windows which
is preferred?

They do the same thing: unlink calls DeleteFile. The only difference is
how errors are reported.

For portability, os.unlink is preferred.

Regards,
Martin
 
T

Tim Roberts

rbt said:
Can someone detail the differences between these two? On Windows which
is preferred?

os.unlink() calls unlink() in the C run-time library. In VC++, unlink()
passes its parameter directly to DeleteFile. There is no difference.
DeleteFile() is the only way to delete files on Windows.

However, if you call os.unlink(), your script will ALSO work in Linux.
win32api.DeleteFile() makes your script Windows-only.
Also, is it true that win32api.DeleteFile() can remove the 'special'
files located in the 'special' folders only accessible by the shell
object such as Temporary Internet Files, etc.

"Temporary Internet Files" is a perfectly normal directory, living at
"\Documents and Settings\username\Local Settings\Temporary Internet Files".
It happens to be marked with the "system" attribute ('attrib +s'), but that
doesn't make it special.

Now, there certainly ARE special shell folders that do not exist in the
file system. Control Panel and My Network Places are two examples.
DeleteFile cannot touch those. You must use shell APIs.
 
T

Tim Golden

[rbt]

| Can someone detail the differences between these two? On
| Windows which is preferred?

Looks like that's been answered elsewhere.

| Also, is it true that win32api.DeleteFile() can remove the 'special'
| files located in the 'special' folders only accessible by the shell
| object such as Temporary Internet Files, etc.

Generally, you want to look at the functions
in the shell module from pywin32 for these.
Specifically, look at

[using: from win32com.shell import shell, shellcon
because I always forget *which* is the shell module
I need to import]

shell.SHGetSpecialFolderLocation
shell.SHFileOperation

The former will find the "real" location of various
special-looking folders. The latter will move/copy etc.
through the shell which means, among other things, that
you'll see the "flying folders" animated icon.

TJG
 
R

rbt

Tim said:
[rbt]

| Can someone detail the differences between these two? On
| Windows which is preferred?

Looks like that's been answered elsewhere.

| Also, is it true that win32api.DeleteFile() can remove the 'special'
| files located in the 'special' folders only accessible by the shell
| object such as Temporary Internet Files, etc.

Generally, you want to look at the functions
in the shell module from pywin32 for these.
Specifically, look at

[using: from win32com.shell import shell, shellcon
because I always forget *which* is the shell module
I need to import]

shell.SHGetSpecialFolderLocation
shell.SHFileOperation

The former will find the "real" location of various
special-looking folders. The latter will move/copy etc.
through the shell which means, among other things, that
you'll see the "flying folders" animated icon.

TJG

Thanks for the explanation guys!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top