Number of file in Temporary Internet File

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Julien Morel.

Hello,
I want to know the number of file in "Temporary Internet File" then to erase them.
Is what my code is good, I am not able to make it walk.
Thank

In french
J'essaye de savoir le nombre de fichier qui sont présent dans le dossier temporare d'internet, pour
ensuite les effacer, mon code me retourne 1 à chaque fois. Si je change de dossier, par exemple celui
de Windows, le code marche
Merci de votre aide




Structure EMID
cb.b
abID.b[1]
EndStructure

Structure ITEMIDLIST
mkid. EMID
EndStructure

Procedure.s GetSystemFolder (folder)
*itemid.ITEMIDLIST = #NULL
If SHGetSpecialFolderLocation_ (0, folder, @*itemid) = #NOERROR
location$ = Space (#MAX_PATH)
If SHGetPathFromIDList_ (*itemid, @location$)
ProcedureReturn location$
EndIf
EndIf
EndProcedure


#CSIDL_INTERNET_CACHE=$20

temp$=GetSystemFolder (#CSIDL_INTERNET_CACHE)


ExamineDirectory(0,temp$,"*.*")

Repeat



FileType = NextDirectoryEntry()
If FileType=1
nb=nb+1
EndIf


If FileType = 0
Goto stop_temp
EndIf


ForEver






stop_temp:


nb$=Str(nb)
MessageRequester ("","Patch is "+temp$+Chr(10)+Chr(10)+"Number of files : "+nb$, #MB_ICONINFORMATION)




Forum in French
http://www.forumpurebasic.fr.st
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Denis.

Salut Julien,

i think that the problem is elsewhere. Some months ago i get the same problem. Looking for why, i've found on MS SDK plateform some infos abouts specific files. So, i think that the files that are internet links etc, are considered as object. I think (but i'm not sur) that you may use IShellFolder Interface (object oriented) to get right infos.
But PB is actually not object oriented and you must write your own lib or ask for Fred or a C GURU coder to code it.

If you have Winrar, use it and open the following folder
c:\Windows\Temporary Internet Files
You wont see the internet files. Folder is almost empty but if you use window exploreur, you will see all files.


Here is an exemple in C (IShellFolder Interface)

http://www.codeproject.com/shell/namespcextguide1.asp

Here is the MS doc

http://msdn.microsoft.com/library/defau ... folder.asp



Denis
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

This should work here (Windows 98), but it doesn't. Can you test it? (debugger on)

Code: Select all

#CSIDL_INTERNET_CACHE = $20

#SHCONTF_FOLDERS = $20
#SHCONTF_NONFOLDERS = $40
#SHCONTF_INCLUDEHIDDEN = $80
#SHCONTF_INIT_ON_FIRST_NEXT = $100
#SHCONTF_STORAGE = $800

#Release = 8
#Alloc = 12
#BindToObject = 20
#Next = 16
#Free = 20
#EnumObjects = 16

CoInitialize_(0)
ppenumIDList.l
pMalloc.l
ppshf.l
SHGetMalloc_(@pMalloc)
hres = SHGetSpecialFolderLocation_(0, #CSIDL_INTERNET_CACHE, @ppidl)
If hres=#S_OK
  pszDisplayName = AllocateMemory(0, #MAX_PATH)
  If SHGetPathFromIDList_(ppidl, pszDisplayName)
    Debug PeekS(pszDisplayName)
    Debug ""
  EndIf
  FreeMemory(0)
  If SHGetDesktopFolder_(@ppshf)=#NOERROR And ppshf And ppidl
    ppvOut.l
    If CallCOM(#BindToObject, ppshf, ppidl, 0, ?IID_IShellFolder, @ppvOut)=#NOERROR
      CallCOM(#Release, ppshf)
      CallCOM(#Free, pMalloc, ppidl)
      CallCOM(#Release, pMalloc)
      If ppvOut
        If CallCOM(#EnumObjects, ppvOut, 0, #SHCONTF_FOLDERS|#SHCONTF_NONFOLDERS|#SHCONTF_INCLUDEHIDDEN|#SHCONTF_INIT_ON_FIRST_NEXT|#SHCONTF_STORAGE, @ppenumIDList)=#NOERROR
          If ppenumIDList
            ItemCount = 0
            enumerating = 1
            pszDisplayName = AllocateMemory(0, #MAX_PATH)
            While enumerating
              hres = CallCOM(#Next, ppenumIDList, 1, @ppidl, 0) ; this is the function failing
              Select hres
                Case #NOERROR
                  SHGetMalloc_(@pMalloc)
                  If SHGetPathFromIDList_(ppidl, pszDisplayName)
                    Debug PeekS(pszDisplayName)
                  EndIf
                  CallCOM(#Free, pMalloc, ppidl)
                  CallCOM(#Release, pMalloc)
                  ItemCount+1
                Case #S_FALSE
                  CallCOM(#Free, pMalloc, ppidl)
                  CallCOM(#Release, pMalloc)
                  Debug "Temporary Internet Files folder holds "+Str(ItemCount)+" items."
                  enumerating = 0
                Default
                  If hres=$80004001
                    ErrorString$ = "not implemented."
                  Else
                    ErrorString$ = Hex(hres)
                  EndIf
                  Debug "Error: "+ErrorString$
                  enumerating = 0
              EndSelect
            Wend
            FreeMemory(0)
          EndIf
          CallCOM(#Release, ppenumIDList)
        EndIf
        CallCOM(#Release, ppvOut)
      EndIf
    EndIf
  EndIf
EndIf
CoUnInitialize_()

End

!section '.data' Data readable writeable
IID_IShellFolder:
!dd $000214E6
!dw 0, 0
!db $0C0, 0, 0, 0, 0, 0, 0, $046
El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Julien Morel.

No Work in XP


Forum in French
http://www.forumpurebasic.fr.st
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Manolo.

No work in 2000 Professional + NT

Manolo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

Ok, I get it: it doesn't work XD

El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

Check this (a bit tricky, but seems to work):

Code: Select all

; Comments: Usual folder location/Minimum OS version required (if not stated, Windows 95, NT or later)
#CSIDL_DESKTOP = 0
#CSIDL_INTERNET = $0001 ; Internet Explorer (icon on desktop)
#CSIDL_PROGRAMS = $0002 ; Start Menu\Programs
#CSIDL_CONTROLS = $0003 ; My Computer\Control Panel
#CSIDL_PRINTERS = $0004 ; My Computer\Printers
#CSIDL_PERSONAL = $0005 ; My Documents
#CSIDL_FAVORITES = $0006 ; \Favorites
#CSIDL_STARTUP = $0007 ; Start Menu\Programs\Startup
#CSIDL_RECENT = $0008 ; \Recent
#CSIDL_SENDTO = $0009 ; \SendTo
#CSIDL_BITBUCKET = $000a ; \Recycle Bin
#CSIDL_STARTMENU = $000b ; \Start Menu
#CSIDL_MYDOCUMENTS = $000c ; logical "My Documents" desktop icon
#CSIDL_MYMUSIC = $000d ; "My Music" folder
#CSIDL_MYVIDEO = $000e ; "My Videos" folder
#CSIDL_DESKTOPDIRECTORY = $0010 ; \Desktop
#CSIDL_NETWORK = $0012 ; Network Neighborhood (My Network Places)
#CSIDL_NETHOOD = $0013 ; \nethood
#CSIDL_FONTS = $0014 ; windows\fonts
#CSIDL_TEMPLATES = $0015
#CSIDL_COMMON_STARTMENU = $0016 ; All Users\Start Menu
#CSIDL_COMMON_PROGRAMS = $0017 ; All Users\Start Menu\Programs
#CSIDL_COMMON_STARTUP = $0018 ; All Users\Startup
#CSIDL_APPDATA = $001a ; 4.71 \Application Data
#CSIDL_COMMON_DESKTOPDIRECTORY = $19
#CSIDL_DRIVES = $11 ; My Computer
#CSIDL_HISTORY = $22
#CSIDL_INTERNET_CACHE = $20 ; 4.72
#CSIDL_LOCAL_APPDATA = $1c ; 5.00
#CSIDL_MYPICTURES = $27; 5.00
#CSIDL_PRINTHOOD = $1b
#CSIDL_ALTSTARTUP = $1d
#CSIDL_COMMON_ALTSTARTUP = $1e
#CSIDL_COMMON_FAVORITES = $1f
#CSIDL_COOKIES = $21
#CSIDL_COMMON_APPDATA = $23 ; 5.00
#CSIDL_WINDOWS = $24 ; 5.00 GetWindowsDirectory_()
#CSIDL_SYSTEM = $25 ; 5.00 GetSystemDirectory_()
#CSIDL_PROGRAM_FILES = $26 ; 5.00
#CSIDL_PROFILE = $28 ; 5.00
#CSIDL_SYSTEMX86 = $29 ; x86 system directory on RISC
#CSIDL_PROGRAM_FILESX86 = $2a ; x86 C:\Program Files on RISC
#CSIDL_PROGRAM_FILES_COMMON = $2b ; 5.00
#CSIDL_PROGRAM_FILES_COMMONX86 = $2c ; x86 Program Files\Common on RISC
#CSIDL_COMMON_TEMPLATES = $2d
#CSIDL_COMMON_DOCUMENTS = $002e ; All Users\Documents
#CSIDL_COMMON_ADMINTOOLS = $002f ; 5.00 All Users\Start Menu\Programs\Administrative Tools
#CSIDL_ADMINTOOLS = $0030 ; 5.00 \Start Menu\Programs\Administrative Tools
#CSIDL_CONNECTIONS = $0031 ; Network And Dial-up Connections
#CSIDL_COMMON_MUSIC = $0035 ; All Users\My Music
#CSIDL_COMMON_PICTURES = $0036 ; All Users\My Pictures
#CSIDL_COMMON_VIDEO = $0037 ; All Users\My Video
#CSIDL_RESOURCES = $0038 ; Resource Directory
#CSIDL_RESOURCES_LOCALIZED = $0039 ; Localized Resource Directory
#CSIDL_COMMON_OEM_LINKS = $003a ; Links to All Users OEM specific apps
#CSIDL_CDBURN_AREA = $003b ; USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
; unused = $3c
#CSIDL_COMPUTERSNEARME = $003d ; Computers Near Me (computered from Workgroup membership)
#CSIDL_FLAG_CREATE = $8000 ; 5.00 combine with CSIDL_ value to force folder creation in SHGetFolderPath()
#CSIDL_FLAG_DONT_VERIFY = $4000 ; combine with CSIDL_ value to return an unverified folder path
#CSIDL_FLAG_NO_ALIAS = $1000 ; combine with CSIDL_ value to insure non-alias versions of the pidl
#CSIDL_FLAG_PER_USER_INIT = $0800 ; combine with CSIDL_ value to indicate per-user init (eg. upgrade)
#CSIDL_FLAG_MASK = $FF00 ; mask for all possible flag values

SpecialFolderTest = #CSIDL_FONTS

#SHCONTF_FOLDERS = $20
#SHCONTF_NONFOLDERS = $40
#SHCONTF_INCLUDEHIDDEN = $80
#SHCONTF_INIT_ON_FIRST_NEXT = $100
#SHCONTF_STORAGE = $800

#IUnknown_Release = 8
#IMalloc_Alloc = 12
#IMalloc_Free = 20
#IShellFolder_EnumObjects = 16
#IShellFolder_BindToObject = 20
#IShellFolder_GetDisplayNameOf = 44
#IEnumIDList_Next = 12

CoInitialize_(0)
ppenumIDList.l
pMalloc.l
ppshf.l
pppf.l
SHGetMalloc_(@pMalloc)
hres = SHGetSpecialFolderLocation_(0, SpecialFolderTest, @ppidl)
If hres=#S_OK
  pszDisplayName = AllocateMemory(0, (#MAX_PATH*2)+2)
  If SHGetPathFromIDList_(ppidl, pszDisplayName)
    FolderPath$ = PeekS(pszDisplayName)
    Debug FolderPath$
    Debug ""
  EndIf
  FreeMemory(0)
  If SHGetDesktopFolder_(@ppshf)=#NOERROR And ppshf And ppidl
    ppvOut.l
    If CallCOM(#IShellFolder_BindToObject, ppshf, ppidl, 0, ?IID_IShellFolder, @ppvOut)=#NOERROR
      CallCOM(#IUnknown_Release, ppshf)
      CallCOM(#IMalloc_Free, pMalloc, ppidl)
      CallCOM(#IUnknown_Release, pMalloc)
      If ppvOut
        If CallCOM(#IShellFolder_EnumObjects, ppvOut, 0, #SHCONTF_FOLDERS|#SHCONTF_NONFOLDERS|#SHCONTF_INCLUDEHIDDEN|#SHCONTF_INIT_ON_FIRST_NEXT|#SHCONTF_STORAGE, @ppenumIDList)=#NOERROR
          If ppenumIDList
            ItemCount = 0
            enumerating = 1
            pszDisplayName = AllocateMemory(0, (#MAX_PATH*2)+2)
            While enumerating
              hres = CallCOM(#IEnumIDList_Next, ppenumIDList, 1, @ppidl, 0)
              Select hres
                Case #NOERROR
                  SHGetMalloc_(@pMalloc)
                  If SHGetPathFromIDList_(ppidl, pszDisplayName)
                    DisplayName$ = PeekS(pszDisplayName)
                    Debug GetFilePart(DisplayName$)
                  EndIf
                  CallCOM(#IMalloc_Free, pMalloc, ppidl)
                  CallCOM(#IUnknown_Release, pMalloc)
                  ItemCount+1
                Case #S_FALSE
                  CallCOM(#IMalloc_Free, pMalloc, ppidl)
                  CallCOM(#IUnknown_Release, pMalloc)
                  Debug ""
                  Debug FolderPath$+" holds "+Str(ItemCount)+" items."
                  enumerating = 0
                Default
                  If hres=$80004001
                    ErrorString$ = "not implemented."
                  Else
                    ErrorString$ = Hex(hres)
                  EndIf
                  Debug "Error: "+ErrorString$
                  enumerating = 0
              EndSelect
            Wend
            FreeMemory(0)
          EndIf
          CallCOM(#IUnknown_Release, ppenumIDList)
        EndIf
        CallCOM(#IUnknown_Release, ppvOut)
      EndIf
    EndIf
  EndIf
EndIf
CoUnInitialize_()

End

!section '.data' Data readable writeable
IID_IShellFolder:
!dd $000214E6
!dw 0, 0
!db $0C0, 0, 0, 0, 0, 0, 0, $046
El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Denis.

Hi El_Choni,
it's a nice work.

I try your code.

First, it doesn't compile because GetSystemInfo_( hasn't parameter.

Case #S_FALSE
CallCOM(#IMalloc_Free, pMalloc, ppidl)
CallCOM(#IUnknown_Release, pMalloc)
Debug ""
Debug FolderPath$+" holds "+Str(ItemCount)+" items."
enumerating = 0 GetSystemInfo_(
I try with GetSystemInfo_(@ppidl).
It works for some #CSIDL_ constants but i Try with this one:

SpecialFolderTest = #CSIDL_INTERNET_CACHE ;(= $20)

And the result is the same as examineDirectory(). It doesn't display files wich are internet link (objects ?)


Denis



Bonne journée.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

Hi,

forget about GetSystemInfo_(, it's only there because I wanted to look up that function in WIN32.HLP and forgot to delete it (I did it now).

#CSIDL_INTERNET_CACHE doesn't work in versions prior to 4.72, check your OS version.

El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Denis.

Hi El_Choni,

i will take a look to my Os version.

Thanks again for infos


Denis

Bonne journée.
Post Reply