Closing Opened Files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi people,

I have an automatic process which runs every day at 6:00 PM on several files
of my computer. The success of this process depends on the availability of
these files: they should not be in a opened state while the process begins.

I know that NET FILE command lists all the opened files on my PC an the ids
of these "processes". I can use NET FILE ID /CLOSE to close that open session
with my files, but this is a manual procedure.

I need to automate this procedure: close all the sessions which have my
files opened, through a script.

Can anyone give me any help how to accomplish this?

Thanks a lot
 
From a command prompt;
net sess /d /y

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| Hi people,
|
| I have an automatic process which runs every day at 6:00 PM on several
files
| of my computer. The success of this process depends on the availability of
| these files: they should not be in a opened state while the process
begins.
|
| I know that NET FILE command lists all the opened files on my PC an the
ids
| of these "processes". I can use NET FILE ID /CLOSE to close that open
session
| with my files, but this is a manual procedure.
|
| I need to automate this procedure: close all the sessions which have my
| files opened, through a script.
|
| Can anyone give me any help how to accomplish this?
|
| Thanks a lot
|
 
Hello Gabriel,
If you have Python installed (www.python.org) , the following script works
on my machine. This script assumes that a file id is not more than 4 digits
long. Let me know if you have questions.
Louis

-----begin script-----
import os
filelist=["yourfilenamesgohere", "andhere", "andhere", "etc"]
openfiles=os.popen('net file')
for lines in openfiles:
for files in filelist:
if files in lines:
fileid=int(lines[:5])
command='net file ' + str(fileid) + ' /close'
os.popen(command)
-----end script-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top