Matching Folders and Files Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
TheTrueKey
Posts: 7
Joined: 15 Apr 2017, 15:37

Matching Folders and Files

15 Apr 2017, 16:28

Hey,

How would you move files into a folder that have matching numbers.

Example:
###-folder
file_###.ext
---------------------------
###-folder\file_###.ext

Thanks
Last edited by TheTrueKey on 16 Apr 2017, 05:55, edited 5 times in total.
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Move files with match into a folder with same match  Topic is solved

15 Apr 2017, 17:37

Hello, I've written a quick script for you that may be useful

I'm not exactly sure what you were asking so let me know if you still need help.

EDIT: updated code

Code: Select all

dir_input := "tester\folder1"  ;change this or add uncomment the fileselectfolder
dir_output := "tester\folder2" ;change to output folder
return

f1::
;FileSelectFolder,dir_input
loop,files,%dir_input%\*.*,R  ;looping files from dir_input recursing into folder
{
	if RegExMatch(A_LoopFileName,"(\d+)",match) { ;if #####- is found ie   nn11(77777-)name.txt
		if (strlen(match1) > 4) {  ;if found numbers are 5 or higher
			numbers := SubStr(match1,strlen(match1)-4)  ;put the right five numbers into a variable
			IfNotExist,%dir_output%\%numbers% ;if folder not exist, create it
				FileCreateDir,%dir_output%\%numbers%
			filemove,%A_LoopFileFullPath%,%dir_output%\%numbers%
		}
	}
}
return

f9::reload
Last edited by Spawnova on 15 Apr 2017, 20:27, edited 2 times in total.
TheTrueKey
Posts: 7
Joined: 15 Apr 2017, 15:37

Re: Move files with match into a folder with same match

15 Apr 2017, 18:32

Hey Spawn thanks for the reply and script. I thought that might be confusing.

### = random digits

A folder named "###-folder" and any files with the same ### in the name, for example "NN111###-file.ext" get moved to "###-folder".
Last edited by TheTrueKey on 16 Apr 2017, 06:03, edited 1 time in total.
User avatar
Spawnova
Posts: 557
Joined: 08 Jul 2015, 00:12
Contact:

Re: Move files with match into a folder with same match

15 Apr 2017, 20:26

Okay, I see now.

Although I'm not sure how your files will be formatted, do you always need only the 5 last numbers?
If so, I've edited the script in my previous post to reflect that.
It will look for a string of numbers larger than 4 (5+) and get the 5 last digits and move the file to that folder, hopefully that helps out.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Rohwedder and 372 guests