watch a folder ONLY for file renaming Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

watch a folder ONLY for file renaming

02 Mar 2020, 07:58

Hi all,
I'm planning to essemble a script to get "play a sound when any download finished", that is:
monitor files extension changing in a folder - this folder is a download target folder (both as temporary file and target folder), when a download begins, a new temp file, say ABC.ZIP.FDMDOWNLOAD will be added to here, when download done, it will be renamed to ABC.ZIP

My intention is to detect this kind of renaming ONLY. And forget about this "FDMDOWNLOAD", it doesn't need to be detail specific - any file renaming in this folder is good enough - will cause a song play.
And: any file added to this folder should not trigger alarm.
No subfolder needs to be monitored.

I was thinking about scanning the whole folder again and again. Then I searched about "FindFirstChangeNotificationW", then "ReadDirectoryChangesW". I have to admit this windows API thing is over me.

Could anybody please help?
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Re: watch a folder ONLY for file renaming  Topic is solved

02 Mar 2020, 08:45

This will give you some ideas

Code: Select all

Loop
{
Sleep,1000
IfNotExist,X:\*.ABC.ZIP.FDMDOWNLOAD
{
SoundPlay,C:\Windows\media\Windows Logon.wav,wait
Break
}
}
Once the file that ends with ABC.ZIP.FDMDOWNLOAD in X:\ disappear for whatever reason(including renaming which is also like moving it or deleting it),a sound will play and break the loop
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: watch a folder ONLY for file renaming

02 Mar 2020, 08:53

You can take a look at WatchDirectory by HotKeyIt
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

Re: watch a folder ONLY for file renaming

02 Mar 2020, 09:02

Thank you, sir. That's neat and simple. Although I sometimes have more than one download task simutaneously, I just need an alert when all of them done. So, great tip!
User avatar
boiler
Posts: 16913
Joined: 21 Dec 2014, 02:44

Re: watch a folder ONLY for file renaming

02 Mar 2020, 10:14

You might want to check out the updated version of WatchDirectory called WatchFolder by just me.
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: watch a folder ONLY for file renaming

02 Mar 2020, 10:39

Thanks boiler. I forgot that one, I even use it in one of my script. I'm gettin' old.
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
boiler
Posts: 16913
Joined: 21 Dec 2014, 02:44

Re: watch a folder ONLY for file renaming

02 Mar 2020, 10:49

Odlanir wrote:
02 Mar 2020, 10:39
I'm gettin' old.
I know the feeling. :D
User avatar
Jovannb
Posts: 268
Joined: 17 Jun 2014, 02:44
Location: Austria

Re: watch a folder ONLY for file renaming

02 Mar 2020, 11:28

Hi,

what I can imagine:
a) you remember per file: file size, creation-time-stamp and name
b) as soon as name changes and file size and creation-time-stamp stays the same values then
c) you know that somebody changed the name of a certain file
the probability, that you have files with same file size and creation-time is against zero.
If there is a file, for which you havent remembered (stored) file size and creation time, then it is a new file and not a file-name-change

So that should work (from a logicial perspective)

J.B.
AHK: 1.1.37.01 Ansi, 32-Bit; Win10 22H2 64 bit, german
joshatt
Posts: 151
Joined: 07 Dec 2014, 08:41

Re: watch a folder ONLY for file renaming

02 Mar 2020, 23:39

Thanks guys.
I'll keep those powerful and complicated for later study.
My try based on @vsub's enlightenment:

Code: Select all

#Persistent

	Loop
	{
		Sleep,1000
		If FileExist("H:\*.fdmdownload")
		{
			laststatus := 1
			Continue
		}
		If ( !FileExist("H:\*.fdmdownload") and laststatus=1 )
		{
		     ;SoundPlay,C:\Windows\media\Windows Logon.wav,wait
			;yeah, my soundplay stops working,too, no idea.
			vPath := "d:\alert7.wav"
			vRet := DllCall("winmm\PlaySound" (A_IsUnicode?"W":"A"), Str,vPath, Ptr,0, UInt,0x20000)
			laststatus := 0
			Continue
		}
	}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, roeleboele and 394 guests