Folder path+Folder count+File name checking script

The challenge - I’m looking for a script that can detect if any of the following fail:

Count folders in file path
-If the folder count doesn’t equal 6 folders in file path = fail
Check for empty folders
-If no file exists with “.mov” extension in the 6th folder of each folder hierarchy = fail
Check file name and extensions
-If a file with the extension “.mov” doesn’t contain “x1080” in the file name in the 6th folder of each folder hierarchy = fail
-If a file with the extension “.mov” doesn’t contain “format_prores” in the file name in the 6th folder of each folder hierarchy = fail
-If a file with the extension “.r3d” doesn’t contain “format_red” in the file name in the 6th folder of each folder hierarchy = fail
-If any file name contains “res_-fps” = fail
-If any file name contains “res_x-fps” = fail
-If any file with the file name “fps_25” = fail
-If any file with the file name “_0.mov” = fail
Generate Reports on fail
-If anything fails, generate list/report of all the file paths that failed in a pop-up/alert box
-Continue to check all, even if after any fails have been detected

Any help would be incredible!!

What is the original info ?

Is it an available list of paths, the contents of a given folder . ?

Without this info it would be difficult to answer your questions.

Are you sure of this requirement :
-If any file with the file name “fps_25” = fail
I’m surprised to see a filename with no name extension.

Yvan KOENIG running Sierra 10.12.1 in French (VALLAURIS, France) mardi 29 novembre 2016 19:28:43

Looks like this script is working if I select the 6th folder, but I need to select “folder 1” and see if there are 6 folders to the end of the folder structure (reading it the opposite direction you have it set up). The script needs to be able to read every folder after “folder 1” for fails.

-In the 6th folder, it must contain 1 file with the extension .mov and in the file name “x1080”. If it doesn’t = fail.
–The folder can have more than 1 file with different file names though, and that’s ok (look at image below).
-The 6th folder should never contain more than 3 files

set text item delimiters to ":"
set errRpt to "FAILS LIST:" & return
 
set ff to (choose folder) as alias
 
tell application "Finder"
  set numFldrs to ((ff as text)'s text items's length) - 5 -- don't count path to top folder, or final "empty" item
  set movFileCnt to 0
 
  repeat with f in ff's files as alias list
  set {fNam, fExt} to {f's name, f's name extension}
  set AppleScript's text item delimiters to "." & fExt
  set fNam to fNam's text item 1 --> name stripped of extension
 
  set fail to false
  set fail to ¬
  (fExt is "mov" and fNam does not contain "x1080") or ¬
  (fExt is "mov" and fNam does not contain "format_prores") or ¬
  (fExt is "r3d" and fName does not contain "format_red") or ¬
  fNam contains "res_-fps" or ¬
  fNam contains "res_x-fps" or ¬
  fNam contains "fps_25" or ¬
  fNam & "." & fExt is "_0.mov"
  if fail is true then set errRpt to errRpt & ff & fNam & "." & fExt & return
 
  if fExt is "mov" then set movFileCnt to movFileCnt + 1
 
  end repeat
end tell
 
if movFileCnt is 0 then set errRpt to errRpt & "No .mov files in folder" & return
if numFldrs is not 6 then set errRpt to errRpt & "Not 6 folders in path" & return
 
set the clipboard to errRpt
display dialog errRpt buttons "OK"
return errRpt

As I’m not sure of what you want to achieve, I post a script scanning every folder embedded in the selected one.
You will have to add the code required to treat each of these folders.

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"


set rootFolder to (choose folder)

set rootPosixPath to POSIX path of rootFolder

(* Scan the folders of the root one *)
set |⌘| to current application
-- Set up an NSFileManager enumerator and get the root folder's "new entire contents" (visible files and folders) as NSURLs.
set theFileManager to |⌘|'s class "NSFileManager"'s defaultManager()
set rootURL to |⌘|'s |NSURL|'s fileURLWithPath:(rootPosixPath)
set dirAndPackageKeys to |⌘|'s class "NSArray"'s arrayWithArray:({|⌘|'s NSURLIsDirectoryKey, |⌘|'s NSURLIsPackageKey})
set theEnumerator to theFileManager's enumeratorAtURL:(rootURL) includingPropertiesForKeys:(dirAndPackageKeys) options:((|⌘|'s NSDirectoryEnumerationSkipsHiddenFiles) + (|⌘|'s NSDirectoryEnumerationSkipsPackageDescendants as integer)) errorHandler:(missing value)
set isFolderDict to |⌘|'s |NSDictionary|'s dictionaryWithObjects:({true, false}) forKeys:(dirAndPackageKeys) -- directory yes, package no
repeat
	set anURL to theEnumerator's nextObject()
	if anURL is missing value then exit repeat
	set dpDictionary to (anURL's resourceValuesForKeys:(dirAndPackageKeys) |error|:(missing value))
	if ((dpDictionary's isEqualToDictionary:isFolderDict) as boolean) then
		my treat(item 1 of (anURL as list))
	end if
end repeat
my treat(rootFolder) # Don't forget the root one

#=====

on treat(afolder)
	# Split the pathname into its components
	set folderComponents to my decoupe(afolder as text, ":")
	# Grab the count of these components
	set nbComponents to count folderComponents
	# Now do your duty upon this folder
	# .
	# .
end treat

#=====

on decoupe(t, d)
	local oTIDs, l
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set l to text items of t
	set AppleScript's text item delimiters to oTIDs
	return l
end decoupe

#=====

Some hours ago I posted a script doing the same job but requiring BridgePlus.
This time BridgePlus is not required, but the code is longer.
I didn’t compared the speed of the two versions.

Yvan KOENIG running Sierra 10.12.1 in French (VALLAURIS, France) mercredi 30 novembre 2016 21:47:05