still puzzled howto exclude hidden files....

I could really use some help with excluding hidden files (searching on a NAS/FAT) with my script
I added " -type f ! -name ‘.*’‘’ in the do shell script find but i still get the files starting with a dot in the list
looked all over and in the man of find but I just can’t get it to work
Also… how do I write the name of file(s) not found to the log?

here is the script soo far:

property theSDirectory : "/Volumes"
property noSearch : "/Volumes/Macintosh HD"

set theVideos to text returned of (display dialog "looking for video?" default answer "" buttons {"ok", "cancel"} cancel button "cancel" default button 1)

set oldDels to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
set theVideolist to every text item of theVideos
set AppleScript's text item delimiters to "|"
set theVideolist to theVideolist as string
set AppleScript's text item delimiters to oldDels
set theLog to (do shell script "touch " & "~/Desktop/notFound.txt ")
set regex to theSDirectory & "/.*(" & theVideolist & ").*"

set master_list to paragraphs of (do shell script "/usr/bin/find -E " & quoted form of theSDirectory & " -type f ! -name '.*'  -path " & quoted form of noSearch & " -prune " & " -o " & " -iregex " & quoted form of regex & " -print ")

set selected to choose from list master_list ¬
	with prompt "Please select:" with multiple selections allowed
set listSize to (count of selected) as string
if selected is false then return

set Destination to choose folder with prompt "Choose your Destination:"
set loopCount to "0" as number

set ProgressBar to load script alias (((path to scripts folder) as text) & "Lib:BP Progress Bar Controller.scpt")
tell ProgressBar
	initialize("copy selected videos")
	barberPole(true)
	setStatusTop to "copying..."
	repeat with aPath in selected
		set AppleScript's text item delimiters to "/"
		set filename to last text item of aPath
		set AppleScript's text item delimiters to ""
		set loopCount to ((loopCount) + 1)
		setMax to listSize
		setStatusTop to "moving: " & filename & " --> " & quoted form of (POSIX path of Destination)
		setStatusBottom to "Number of Items: " & loopCount & " of " & listSize
		do shell script "/bin/cp " & quoted form of aPath & space & quoted form of (POSIX path of Destination)
		increase by 1
	end repeat
	tell ProgressBar to quit
	display dialog "Videos are copied" buttons {"OK"} default button 1
	do shell script "open " & quoted form of (POSIX path of Destination)
end tell

thanks in advance!!!

the ! -name ‘.*’ syntax should work.
Maybe there is an interference with the regex expression which I’m not familiar with at all

You can included and exclude everything with the regex, just change it to:

set regex to theSDirectory & "/[^\\.].*(" & theVideolist & ").*"

and forget the whole “! -name ‘.*’”

hi DJ Bazzie Wazzie
tried this:

set regex to theSDirectory & "/[^\\.].*(" & theVideolist & ").*"

set master_list to paragraphs of (do shell script "/usr/bin/find -E " & quoted form of theSDirectory & " -path " & quoted form of noSearch & " -prune " & " -o " & " -iregex " & quoted form of regex & " -print ")

but still get blabla AND ._blabla

Out of curiosity, when you run the following script do you see files starting with a “.” as well?

do shell script "find -E $HOME -maxdepth 1 -regex $HOME'/[^\\.].*' -print -prune" 

Hello.

It seems to me that the OP tries to use the not for both name and a path he wants to exclude, now the correct syntax would be in an example I made as I wanted to make it work:

I added the and operator, and I also used parenthesis, it will look like this in a do shell script:

By the way, here is a script for escaping terminal command lines that have been pasted to the clipboard

I think that -o primary’s spurious. Try removing it.

It is the .* causing the problem.

set regex to theSDirectory & "/[^\\.]*(" & theVideolist & ").*"

p.s. it’s a bit tricky, the file name cannot contain a period at all

Hello.

I agree with Nigel, in that the -o probably ruins the whole thing.

The other thing is that even though the ! operator should negate an expression, there is no way I can reproduce the example in the find man page. I have to use the ! for every expression I want to rule out. (I use /usr/bin/find).

I found this page helpful when I googled the problem.

Thanks everyone!

I will look at all proposed solutions and post the outcome
:slight_smile:

I think it does work. Sequences of primaries are ANDed by default, so:

set rootA to (path to desktop)
set rootP to quoted form of text 1 thru -2 of POSIX path of rootA

do shell script "find " & rootP & " ! -name '.*' ! -name '*.JPG'"
--> Find items whose names do not begin with "." AND whose names do not end with ".JPG"

Logically, NOT A AND NOT B is equivalent to NOT (A OR B). So in “find”, to convert a sequence of negated primaries to a singly negated sequence, the implicit ANDs need to be replaced with explicit ORs:

set rootA to (path to desktop)
set rootP to quoted form of text 1 thru -2 of POSIX path of rootA

do shell script "find " & rootP & " \\! \\( -name '.*' -or -name '*.JPG' \\)"
--> Find items whose names don't either begin with "." or end with ".JPG"

outcome soo far:

--set regex to theSDirectory & "/[^\\.].*(" & theVideolist & ").*" changed to

set regex to theSDirectory & "/[^\\.]*(" & theVideolist & ").*"
set master_list to paragraphs of (do shell script "/usr/bin/find -E " & quoted form of theSDirectory & " -path " & quoted form of noSearch & " -prune " & " -o " & " -iregex " & quoted form of regex & " -print ")

this leaves out hidden files but the name cannot contain a . before the given search
1.avatar.mp4 → not found (hmmmm…)
.avatar.mp4 → not found (ok)
avatar.1.mp4 → found (ok)

so search can only come from the first par of the name (not sure if i can live with that but its an improvement)

putting in -type f -! -name ‘.*’ does not work, removing -o gives nothing found

Nigel,
just read your last post and will look into it, thanks

to be continued…

Maybe a bit harsh method but this will work anyway, instead of looking for a complex expression we can also pipe the output to another regex and remove every line that contains “/.” which are paths that contains invisible files.

set regex to theSDirectory & "/.*(" & theVideolist & ").*"

set master_list to paragraphs of (do shell script "/usr/bin/find -E " & quoted form of theSDirectory & " -path " & quoted form of noSearch & " -prune " & " -o " & " -iregex " & quoted form of regex & " -print | grep -v '/\\.'")

OK. Right at the end of the “find” manual, I see it says that -o is an alternative to -or. So. Since -or has a lower precedence than the implicit -ands, the “find” command in the script at the top of this thread .

set master_list to paragraphs of (do shell script "/usr/bin/find -E " & quoted form of theSDirectory & " -type f ! -name '.*' -path " & quoted form of noSearch & " -prune " & " -o " & " -iregex " & quoted form of regex & " -print ")

. effectively means:

Find items in the hierarchy of theSDirectory. These items can be EITHER:

  1. Items whose type is ordinary file AND whose name does not begin with “.” AND whose path matches noSearch AND prune (whatever that means);
    OR alternatively:
  2. Items of any type, name, or path whose paths case-insensitively match regex.

So any items which satisfy EITHER the first filter OR the second are returned.

Does this explain the problem?

If you want an either/or situation, but with names not beginning with “.” in both cases, you’ll either have to parenthesise carefully or use the name filter on both sides of the -o. I can’t show you exactly because I’m not sure exactly what you want.

Hi Nigel,

I think you can add flags as an extra precaution…

set master_list to paragraphs of (do shell script "/usr/bin/find -E " & quoted form of theSDirectory & " -type f -flags nohidden \\! -name \".*\" -path " & quoted form of noSearch & " -prune " & " -o " & " -iregex " & quoted form of regex & " -print ")

Nigel,
this is what i want:
find files containing blabla and skip path /Volumes/MacintoshHD/ AND don’t find (or list) files/folders that start with a . (hidden files/folders)

Skip that exact path or paths beginning with it?

Edit: Forget that. With a “files only” setting, the exact path would be skipped anyway.

Nigel,
i don’t want find to look for files on the internal hd, al files are on a NAS
thats why i added the path and -prune

Well possibly the solution’s this (untested):

set master_list to paragraphs of (do shell script "/usr/bin/find -E " & quoted form of theSDirectory & " -type f ! -name '.*' ! -path " & quoted form of (noSearch & "*") & " -iregex " & quoted form of regex)

I’ve left off -print because it’s superfluous and -prune because I don’t understand what it does. But you can put them back if you like. I haven’t used adayzdone’s -flags suggestion either as I think it would be better to get the rest working first.

I vaguely remember that solving a problem with files within dropbox.