os.unlink() AND win32api.DeleteFile()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rbt

    os.unlink() AND win32api.DeleteFile()

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

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

    Thanks!
  • Martin v. Löwis

    #2
    Re: os.unlink() AND win32api.Delete File()

    rbt wrote:[color=blue]
    > Can someone detail the differences between these two? On Windows which
    > is preferred?[/color]

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

    For portability, os.unlink is preferred.

    Regards,
    Martin

    Comment

    • Tim Roberts

      #3
      Re: os.unlink() AND win32api.Delete File()

      rbt <rbt@athop1.ath .vt.edu> wrote:[color=blue]
      >
      >Can someone detail the differences between these two? On Windows which
      >is preferred?[/color]

      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.Delete File() makes your script Windows-only.
      [color=blue]
      >Also, is it true that win32api.Delete File() can remove the 'special'
      >files located in the 'special' folders only accessible by the shell
      >object such as Temporary Internet Files, etc.[/color]

      "Temporary Internet Files" is a perfectly normal directory, living at
      "\Documents and Settings\userna me\Local Settings\Tempor ary 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, timr@probo.com
      Providenza & Boekelheide, Inc.

      Comment

      • Tim Golden

        #4
        Re: os.unlink() AND win32api.Delete File()

        [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.Delete File() 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.SHGetSpec ialFolderLocati on
        shell.SHFileOpe ration

        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

        Comment

        • rbt

          #5
          Re: os.unlink() AND win32api.Delete File()

          Tim Golden wrote:[color=blue]
          > [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.Delete File() 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.SHGetSpec ialFolderLocati on
          > shell.SHFileOpe ration
          >
          > 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
          >[/color]

          Thanks for the explanation guys!

          Comment

          Working...