Automatically Move files with specific extensions.

Get help with using AutoHotkey and its commands and hotkeys
Bowditch
Posts: 1
Joined: 29 Sep 2020, 08:37

Automatically Move files with specific extensions.

29 Sep 2020, 08:43

Hello,

would like to automatically have certain file extensions (example: jpg) moved from a certain folder to another folder. As soon as the file with that extension in Folder A (with extension jpg) to be moved to Folder B
BoBo
Posts: 5219
Joined: 13 May 2014, 17:15

Re: Automatically Move files with specific extensions.

29 Sep 2020, 09:16

Code: Select all

#Persistent
srcPath := "C:\myImages"
destPath := "D:\myImages\mysubFolder"

SetTimer, TheMover, % 1*60*1000 ; check once every minute
Return

TheMover:
	Loop, Files,% srcPath "\*.jpg"
		FileMove,% A_LoopFileFullPath,% destPath
Return
Untested. Edit/removed redundant code, see @boilers statement below.
User avatar
boiler
Posts: 10745
Joined: 21 Dec 2014, 02:44

Re: Automatically Move files with specific extensions.

29 Sep 2020, 09:50

That should work fine. A couple of suggestions if I may:

You could use WatchFolder() to trigger the subroutine only (and without delay) when there is a change to the folder.

The subroutine doesn’t need the if part because if there are no .jpg files, the loop will execute zero times, so it functions as a built-in conditional as well:

Code: Select all

TheMover:
	Loop, Files,% srcPath "\*.jpg"
		FileMove,% A_LoopFileFullPath,% destPath
Return
BoBo
Posts: 5219
Joined: 13 May 2014, 17:15

Re: Automatically Move files with specific extensions.

29 Sep 2020, 10:14

because if there are no .jpg files, the loop will execute zero times, so it functions as a built-in conditional as wel
:thumbup:

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], lyscop and 60 guests