Wrox Programmer Forums
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 2nd, 2005, 10:33 AM
Authorized User
 
Join Date: Dec 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to eelisMX
Default Track temp files

Hi

The following function determines if file is used by other application, or if it is accessible for binary read.

Code:
Function isFileUsed(ByVal fName As String) As Boolean

        Dim fNum As Integer

        ' supply a file number that is not already in use
        fNum = FreeFile()

        Try
            ' try to open the file for read
            FileOpen(fNum, fName, OpenMode.Binary, OpenAccess.ReadWrite)
            FileClose(fNum)
            ' FileOpen succeeded
            Return False
        Catch
            ' FileOpen failed
            Return True
        End Try
End Function
It works great.
Some applications keep also temp files while they are open (i.e. MS Office).
My problem is that this function will return false for those temp files (not in use), while the main file returns true (when it is open). Does temp file has a special attribute (I tried already the Temporary attr - its not that).
I realized that some of the temp files are hidden, but normal hidden files should pass this function so its not a good option for me.

So, let's put it more clear: Is there a way to track temp files that some applications keep while they're open ?

Thanks:)
 
Old March 2nd, 2005, 11:28 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I suspect the only ways are things like “taking a look around” before and after an app is put into use, knowing the names that that app uses, and so on.

I don't think there is a specific, direct, trustworthy way to do this.

Why do you ask? (It is an unusual question.) Perhaps there is a better way to do what it is that your ultimate goal is. (Plus, I’m curioous...)
 
Old March 3rd, 2005, 02:50 AM
Authorized User
 
Join Date: Dec 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to eelisMX
Default

My main goal is to rearrange bunch of files and relocate them to a new folder (sort of backup and slight modification). I would not like to work with files that are in use by other process (the above function solve it), so there's no idea to pick up their temp backup file.
From checking some of those temp files I found no specific pattern (as you said). Welcome to the Jungle...
Might be the best solution to check that all processes are down before running it.
 
Old March 3rd, 2005, 12:25 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

If you have the authority to do so, you could configure the application that are creating the temp files to use some other location.
If you only copy the files, then the apps using them would not be affected.
Programming would be easier sometimes if we could just add psychic properties to the code...





Similar Threads
Thread Thread Starter Forum Replies Last Post
track all changes Machiaveli280278 SQL Server 2000 2 September 9th, 2004 04:16 PM
Temp variables???? morpheus SQL Server 2000 7 November 20th, 2003 04:46 PM
Temp Var in For Each pbernardo XSLT 5 November 14th, 2003 06:45 PM
Locked temp files Paul13 ASP.NET 1.0 and 1.1 Basics 0 June 5th, 2003 10:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.