By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 2,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

os.unlink() AND win32api.DeleteFile()

P: n/a
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!
Jan 24 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
rbt wrote:
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
Jan 24 '06 #2

P: n/a
rbt <rb*@athop1.ath.vt.edu> wrote:

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.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jan 24 '06 #3

P: n/a
[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

Jan 24 '06 #4

P: n/a
rbt
Tim Golden wrote:
[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!
Jan 24 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.