• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 922
  • Last Modified:

List of Open Files in Windows using Delphi

I have a backup application. I need to check for open files before taking backup.
One of my customer has 8,00,000 files for backup and this takes an hour to check.

I therefore want to change my logic to checking all open files in the system and then
compare with my setup. (eg: d:\*.* )
1 Solution
8,00,000 files
1. did you mean 8 million or 800 thousand?

2. what mechanism are you using to determine which files are 'open'?

My approach would be to compare the paths of all the open files against the 'tree' of directories to be backed up.
Sinisa VukCommented:
I would go another way. Get list of file handles from windows using NtQuerySystemInformation. Windows keeps it while they are in use. If you get file names with path and compare against yours then there are your files in use...

look this discussions:
more source...

There is a problem with hanging but I work on it to make usable code....
I would go another way
I think we are describing exactly the same 'way'.
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Geert GOracle dbaCommented:
opening the file with exclusive read will only open the file if it is not open

there is no point in making a list of open files first
> it takes a while and the open file list changes in time

while you backup keep a list of files that failed because they were open or in use
when finished re-attempt to backup that list
you could set a number of re-attempts like 10

as a last resort, you could open the file as normal read and try to backup as such
you'd have a list of successful backup files, retried backup files, fuzzy backup files and failed files

Is the order in which the files are backed up important?
Allan_FernandesAuthor Commented:
Good logic. Only changed open mode from 'exclusive read' to 'Deny Write'
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now