Finding files that start with 5 numbers ...

Is it possible to find files that DO NOT CONTAIN in their filename the following things:

  • start with 5 characters that are numbers from 0 to 9
  • 6th character is a letter from a to z (and A to Z)
  • and are situated in a folder called ‘foldername’

Example (to understand my question):
document OK = 27654a-Testprint
document NOT OK = 27854-Testprint

I want to search on an entire volume, and have as result a list or if that is not possible, it should copy the files into a certain directory…

Should this be possible with an applescript?

Hi :slight_smile:

I think you can try the “Osax” of search, like “Find File” (very complete) or “Find Document” (very fast)…
“Find File” : http://microcosmsoftware.com/findfileosax.html
“Find Document” : http://www.lpmi.u-nancy.fr/Find_doc/Find.html

:rolleyes:

As I was browsing this forum I came across your Question, And, luckyly for you, i had just finished a script that did just that (with the only difference that my original script only checked for filenames which started with 7 numbers and a variing name behind the number) I adapted it for your needs, so, here it is:

tell application "Finder"
	choose folder with prompt "Choose the folder to be checked"
	set ChosenFolder to the result
	set X to the name of every item of folder ChosenFolder
	
	set Bad_folder_name to {}
	set Folder_Nummer to {}
	set Folder_letter to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
	repeat with Teller from 1 to (the count of items in X)
		repeat with a from 0 to 9
			if item Teller of X begins with (a as string) then
				repeat with b from 0 to 9
					if item Teller of X begins with (a & b as string) then
						repeat with c from 0 to 9
							if item Teller of X begins with (a & b & c as string) then
								repeat with d from 0 to 9
									if item Teller of X begins with (a & b & c & d as string) then
										repeat with e from 0 to 9
											if item Teller of X begins with (a & b & c & d & e as string) then
												repeat with f from 1 to the count of items in Folder_letter
													if item Teller of X begins with (a & b & c & d & e & (item f of Folder_letter) as string) then
														set Folder_Nummer to Folder_Nummer & (item Teller of X)
													end if
												end repeat
											end if
										end repeat
									end if
								end repeat
							end if
						end repeat
					end if
				end repeat
			end if
		end repeat
	end repeat
	repeat with Good from 1 to (the count of items in X)
		if Folder_Nummer does not contain item Good of X then
			set Bad_folder_name to (Bad_folder_name & (item Good of X as string) as list)
		end if
	end repeat
	if Bad_folder_name = {} then
		display dialog "No bad names found"
	else
		copy every item of Bad_folder_name to resultaat
		choose folder with prompt "Choose Destination For Bad File and Folder Names"
		set Destination to the result
		activate
		repeat with Flets from 1 to (the count of items in resultaat)
			move (every item whose name contains item Flets of resultaat) of ChosenFolder to Destination
		end repeat
	end if
end tell

If you run the script, it will ask you for the folder you want to check, and after checking, if ‘Bad’ names are found, it will ask where you want to put them.

I hope this was what you were looking for.

Good Luck!

Tieke

As I was browsing this forum I came across your Question, And, luckyly for you, i had just finished a script that did just that (with the only difference that my original script only checked for filenames which started with 7 numbers and a variing name behind the number) I adapted it for your needs, so, here it is:

tell application "Finder"
	choose folder with prompt "Choose the folder to be checked"
	set ChosenFolder to the result
	set X to the name of every item of folder ChosenFolder
	
	set Bad_folder_name to {}
	set Folder_Nummer to {}
	set Folder_letter to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
	repeat with Teller from 1 to (the count of items in X)
		repeat with a from 0 to 9
			if item Teller of X begins with (a as string) then
				repeat with b from 0 to 9
					if item Teller of X begins with (a & b as string) then
						repeat with c from 0 to 9
							if item Teller of X begins with (a & b & c as string) then
								repeat with d from 0 to 9
									if item Teller of X begins with (a & b & c & d as string) then
										repeat with e from 0 to 9
											if item Teller of X begins with (a & b & c & d & e as string) then
												repeat with f from 1 to the count of items in Folder_letter
													if item Teller of X begins with (a & b & c & d & e & (item f of Folder_letter) as string) then
														set Folder_Nummer to Folder_Nummer & (item Teller of X)
													end if
												end repeat
											end if
										end repeat
									end if
								end repeat
							end if
						end repeat
					end if
				end repeat
			end if
		end repeat
	end repeat
	repeat with Good from 1 to (the count of items in X)
		if Folder_Nummer does not contain item Good of X then
			set Bad_folder_name to (Bad_folder_name & (item Good of X as string) as list)
		end if
	end repeat
	if Bad_folder_name = {} then
		display dialog "No bad names found"
	else
		copy every item of Bad_folder_name to resultaat
		choose folder with prompt "Choose Destination For Bad File and Folder Names"
		set Destination to the result
		activate
		repeat with Flets from 1 to (the count of items in resultaat)
			move (every item whose name contains item Flets of resultaat) of ChosenFolder to Destination
		end repeat
	end if
end tell

If you run the script, it will ask you for the folder you want to check, and after checking, if ‘Bad’ names are found, it will ask where you want to put them.

I hope this was what you were looking for.

Good Luck!

Tieke