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:\*.* )
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 VukSoftware architectCommented:
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'.
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

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'
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.