Results 1 to 6 of 6
  1. #1
    Join Date
    May 2005
    Posts
    150

    Unanswered: Deleting all .tmp files in a folder

    Anyone have any idea?

    I am trying to check for .tmp files and then delete all of them....

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,420
    Provided Answers: 7
    I know what this has todo with MSaccess

    but
    Code:
    Dim fso, f, f1, fc, s
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set f = fso.GetFolder("C:\Windows\temp") '< =============Set this to the Right Folder
       Set fc = f.Files
       FileCount = 0 
       If Fc.Count <> 0 Then
          For Each File In fc 
          If Instr(ucase(file.name),".TMP")>0 then
          FileCount = FileCOunt + 1
          fso.DeleteFile fso.getfile(File)
          Else
          End if
          Next
         Msgbox("Just Delete " & FileCount & " File(s)") 
    End If
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    May 2005
    Posts
    150
    this has to do with Access because when printing PDFs through Access it creates a temp file... leaving a buildup of temp files in the folder

    thank you for the code

  4. #4
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,420
    Provided Answers: 7
    do you get access to build the PDFs

    if so my bill is

    a copy of the code the does its
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  5. #5
    Join Date
    Nov 2003
    Posts
    1,487
    Just another way...not nearly as compact as what Myles has posted but flexible:

    Code:
    Public Function DeleteAllFiles(PathStrg As String, Optional FileType As String, _
    
    		   Optional Cond As Boolean, Optional ClrAttribures As Integer) As Integer
    
    		 ‘ The “PathStrg” parameter is to hold the string path to the folder the contains 
    
     		‘ the files to delete (ie:  C:\Windows\Temp\”)
    
    
    
    		 ‘ The “FileType” parameter would contain the file name or extension to delete
    
    		 ‘ (ie:  “*.tmp”). The parameter must be a string. Default Type is “*.*”. Any 
    
    		 ‘ wildcard  charcters can be used in the parameter.
    
    
    
    		 ‘ The “Cond” boolean parameter is used to indicate whether or not this
    
    		  ‘ function will carry out a Conditional or Unconditional deletion. If 
    
    		  ‘ set to True, this function will prompt the user to verify deletion and or 
    
    		  ‘ provide the option to cancel the procedure at any time. If set to False (default), 
    
    		  ‘ this function will unconditionally delete all files contained within the
    
    		  ‘ provided path without prompting the user. 
    
    
    
    		 ‘ The optional ClrAttributes parameter, if set to 1, will set all the files contained
    
    		 ‘ withing the supplied path to NORMAL. If set to 0 (default) Attibute modification
    
    		 ‘ is not done.
    
    
    
    		  ‘ Because files which contain the Hidden, Read-Only, or System attributes
    
    		  ‘ can not be deleted with this function, it is recommended that the
    
    		  ‘ ClrAttributes parameter be set to 1 so as to fire the SetAllFileAttributes function 
    
    		 ‘ is used for file attribute modification.
    
    
    
    	  If ClrAttributes = 1 then SetAllFileAttributes(PathStrg)
    
    	  If FileType = ”” Then FileType = “*.*”
    
    	  If Right$(PathStrg, 1) <> "\" Then PathStrg = PathStrg & "\"
    
    		 On Error Resume Next
    
    		 If Cond =True Then
    
    		  	 Dim a$, x As Integer
    
    				Dim Strg As String			   
    
    				a$ = Dir(PathStrg & FileType, 14)
    
    				Do until a$ = “”
    
    				   if a$ <>”” Then 
    
    						Strg = “Are you sure you want to perminently Delete the file “ & a$ & vbCrLf
    
    						Strg = Strg & “located in the folder shown below:?” & vbCrLf & vbCrLf & PathStrg	 
    
    						x = MsgBox (Strg, vbQuestion + vbYesNoCancel, “Are You Sure?”)
    
    						If x = vbCancel Then Err = 1: Exit Do
    
    						If x = vbYes Then Kill PathStrg & a$
    
     			   		If Err Then Err = 0: MsgBox “Error deleting the file “ & a$ & “ (check attributes).”
    
    						a$ = Dir		  
    
     			      End If
    
    				Loop
    
    		 Else
    
    				Kill PathStrg & FileType
    
    		  End if
    
    
    
    		 If Err = 0 Then DeleteAllFiles = 1 Else Err = 0
    
    End Function
    
     
     
    
    Public Function SetAllFileAttributes(PathStrg As String, Optional FAttr As Integer, _
    							 Optional IncludeFolder As Boolean) As Integer
    		‘THE VARIOUS ATTRIBUTES
    
    		‘=======================
    
    		‘0 is Normal (default)
    
     	   ‘1 is Read-only
    
    		‘2 is Hidden
    
    		‘4 is System file
    
    		’32 is Archive
    
    		‘The IncludeFolder will only come into effect if FAttr is not 4 (System).
    
    		PathStrg = Trim(PathStrg)
    
    		If Right$(PathStrg, 1) <> "\" Then PathStrg = PathStrg & "\"
    
    		On Error Resume Next ‘Trap any errors.
    
    		Dim a$
    
    		‘The parameter number 14 tells the DIR function (below) to look
    
    		‘for all files no matter what their current attributes may be.
    
    		a$ = Dir(PathStrg & "*.*", 14) 
    
    		If a$ <> "" Then SetAttr PathStrg & a$, FAttr
    
    		Do Until a$ = “”
    
    				a$ = Dir
    
    				If a$ <> “” Then SetAttr PathStrg & a$, FAttr
    
    		Loop
    
    		If IncludeFolder = True And FAttr <> 4 Then SetAttr Left$(PathStrg, Len(PathStrg) - 1), FAttr
    
    		If err = 0 Then SetAllFileAttributes = 1
    
    End Function


    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


  6. #6
    Join Date
    May 2005
    Posts
    150
    i'm sorry the way I worded it was kind of a c*** tease...

    Acrobat Printer actually creates the PDFs when printing the reports through Access

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •