Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dealing With Variable Folder Name 3

Status
Not open for further replies.

AnotherHiggins

Technical User
Nov 25, 2003
6,259
US
We have recently moved to Lotus Notes.

Whenever you open a file from Lotus, it saves the file in a temp folder. If you open another file with the same name without clearing out the temp folder (which is automatically done on reboot), the file opens with a random string for a name.

This causes me some headaches for reasons I won't go into here.

The trick is that the temp folder has a random element to its name. For example, right now the folder is named notes6030C8. But another time it might be named notesFFF692.

The Notes Temp folder is always in the same parent folder, of course - C:\Documents and Settings\UserName\Local Settings\Temp\

In order to share this with others, I made the UserName dynamic, but I can't work out how to deal with the variable folder name.

What I have so far:
Code:
Sub DeleteTempNotesExcelFiles()

FilePath = "C:\Documents and Settings\" & GetUserName & "\Local Settings\Temp\notes[highlight][red]*[/red][/highlight]"

Dim fs
Set fs = Application.FileSearch
On Error Resume Next
    With fs
        .LookIn = FilePath
        .Filename = "*.xls"
        .Execute
        For i = 1 To .FoundFiles.Count
            Kill .FoundFiles(i)
        Next i
    End With
On Error GoTo 0
Set fs = Nothing

End Sub

But it doesn't accept the wildcard in the folder name. I can understand why: what if there were more than one folder meeting the criteria....

Maybe I could wrap the whole thing in a FileSystemObject and look for the matching folder that way? Is there an easier way?

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
Code:
Sub DeleteTempNotesExcelFiles()
   Dim path_name As String, dir_name As String

   path_name = "C:\Documents and Settings\" & GetUserName  & "\Local Settings\Temp\"
   dir_name = Dir(path_name & "notes*", vbDirectory)
    
   Do While dir_name <> ""
      If GetAttr(path_name & dir_name) = vbDirectory Then
         'Kill path_name & dir_name & "\*.xls"
         
         Debug.Print path_name & dir_name
      End If
        
      dir_name = Dir
   Loop
End Sub
 
Code:
Sub RemoveAllDirectories()

On Error Resume Next
With CreateObject("Scripting.FileSystemObject")
   .DeleteFolder  "C:\Documents and Settings\" & GetUserName  & "\Local Settings\Temp\notes*", True
End with

End Sub

This should delete all temp folders whether or not they have contents.

But if you need to keep the folders and just delete the files use a
Code:
Dim flds As Object

flds= fso.GetFolder("C:\Documents and Settings\" & GetUserName  & "\Local Settings\Temp\")
For Each fld in flds
   If Left(fld.Name, 5) = "notes" Then 
      fso.DeleteFile fld.ParentFolder & "\" & fld.Name & "\*.xls""
   End IF
Next
 
Thanks for your input, everyone.

I can't delete the entire folder because I will be using this code while Lotus Notes is open and there will probably be some files in there that are actually being used.

Here's where I show my ignorance. What is the importance of the following two lines in WinblowsME's code?
[ul]
[li]Debug.Print path_name & dir_name[/li]
[li]dir_name = Dir[/li]
[/ul]


[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
I used the following code for debugging purposes.
Code:
Debug.Print path_name & dir_name

This grabs the next notes* folder.
Code:
dir_name = Dir
 




Hey, WinblowsME, have one on me.

I learned something else today!

Skip,

[glasses] When a wee mystic is on the loose..
It's a Small Medium at Large! [tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top