In use file/folder Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
DataLife
Posts: 460
Joined: 29 Sep 2013, 19:52

Re: In use file/folder

28 Nov 2013, 01:33

Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: In use file/folder

28 Nov 2013, 08:31

For file try this:

Code: Select all

If !f:=FileOpen("C:\Temp\File.txt","w")
  MsgBox Could Not Open File
else f.Close(),f:=""
With regards to Folder, what would be the case when it is in Use? E.g. any of the file is in use?
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: In use file/folder  Topic is solved

28 Nov 2013, 08:43

HotKeyIt wrote:With regards to Folder, what would be the case when it is in Use?
An open command prompt on a folder will make it undeletable.
User avatar
DataLife
Posts: 460
Joined: 29 Sep 2013, 19:52

Re: In use file/folder

28 Nov 2013, 10:14

This works with folders.

MyScripts is the name of a folder.

Code: Select all

IfWinExist,MyScripts
	MsgBox yes
else
	MsgBox no
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
User avatar
DataLife
Posts: 460
Joined: 29 Sep 2013, 19:52

Re: In use file/folder

28 Nov 2013, 10:24

HotKeyIt wrote:For file try this:

Code: Select all

If !f:=FileOpen("C:\Temp\File.txt","w")
  MsgBox Could Not Open File
else f.Close(),f:=""
I made a folder called temp on the root of c:\
then created a text file called file.txt
The script exited with no message with no regard to if the file was opened or not. I also tried it on an existing text file on my desktop.

I am using windows 7 home premium. Ahk version 1.1.13.01 32-bit Ansi
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
Guest

Re: In use file/folder

28 Nov 2013, 15:36

Thanks for trying to help guys,

I need to overwrite all files and folders in a folder/dir only if no files inside that folder/dir/sub folder is in use.
None of the above works.
My solution for now is to try and rename that folder then check errorlevel and then rename it back. But thats too intrusive in my opinion.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: In use file/folder

28 Nov 2013, 18:08

Sorry example was not correct :oops:
See documentation for FileOpen.

Code: Select all

fa:=FileOpen("C:\file.txt","r-rwd") ; comment this line to see the difference
If !(f:=FileOpen("C:\file.txt","r-rwd"))
  MsgBox Could Not Open File
else MsgBox OK
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: In use file/folder

14 Dec 2013, 17:05

What do you mean?
Does it not say OK here?

Code: Select all

If !(f:=FileOpen(A_ScriptFullPath,"r-rwd"))
  MsgBox Could Not Open File
else MsgBox OK
And "Could Not Open File" here?

Code: Select all

fa:=FileOpen(A_ScriptFullPath,"r-rwd")
If !(f:=FileOpen(A_ScriptFullPath,"r-rwd"))
  MsgBox Could Not Open File
else MsgBox OK
Guest

Re: In use file/folder

15 Dec 2013, 03:41

@HotKeyIt,

It just doesn't work, not consistent.
User avatar
noname
Posts: 516
Joined: 19 Nov 2013, 09:15

Re: In use file/folder

15 Dec 2013, 05:18

You can use sysinternals handle.exe and parse the the result.There are plenty of option parameters to configure it.

http://technet.microsoft.com/en-us/sysi ... 96655.aspx
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: In use file/folder

15 Dec 2013, 06:24

Guest wrote:@HotKeyIt,

It just doesn't work, not consistent.
You probably mean that not every program is locking the file, e.g. You can edit and delete a file while it is open in Notepad.
Wade Hatler
Posts: 60
Joined: 03 Oct 2013, 19:49
Location: Seattle Area
Contact:

Re: In use file/folder

15 Dec 2013, 12:16

Agree on using handle.exe as mentioned above. I've been using it for years, and it works in most but not all cases. It always seems to work if a file is being held open by the local file, but doesn't always work when a file is open across the network. It is however the best solution I've found.

One handy trick on it is to run it against a folder. If you do that, it will list all files in that folder that are currently open, which is what I do most of the time. I parse the results, and give the user a chance to close the handle or kill the offending process, then try again in a loop until it's done. I'd give you the code but it's 4NT code, so probably not that useful. Pretty easy to run it with RunWait and parse the results in AHK.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, Bing [Bot], CoffeeChaton, LazyVovchik and 134 guests