question on report of empty folders

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
tiago
Posts: 589
Joined: 14 Feb 2011 21:41

question on report of empty folders

Post by tiago »

Code: Select all

   setting "ShowFolderSizeInList";

   $testfldr = report("{Dir {size b}}");
   IF ($testfldr == "-") { echo "Folder is empty!"; }

   setting "ShowFolderSizeInList", r;
1. Is there a way for this to work without the use of any wait()? This works with stepping on but fails if it's off. The ShowFolderSizeInList setting takes a time to calculate and this is compromising a script of mine in the sense that wait() takes time and ShowFolderSizeInList is not exactly predictable as displayed values will vary depending on how much files are in a given folder.

2. I'm almost sure there's a way to change "-" (previously "empty" afaicr) for anything else, so does anyone knows of a reliable method that can't be fooled by custom empty folder indicators?
Power-hungry user!!!

highend
Posts: 14954
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: question on report of empty folders

Post by highend »

Haven't tried it, but shouldn't a

Code: Select all

setting('BackgroundFileOps', 0);
in front of your script help?
2. I'm almost sure there's a way to change "-" (previously "empty" afaicr) for anything else
Mh, what?

Do you mean:

Code: Select all

IF ($testfldr == "")
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: question on report of empty folders

Post by tiago »

thanks for the hint on 1, I'll try that.

$testfldr = report("{Dir {size b}}"); reports "-" in my system, so "" won't serve. I'm asking if there's a global identifier I can use instead of custom stuff (as I remember XY allows customization on the size field for empty folders but I can't check that for now), so all of this

"nada"
"empty"
"null"
"-"
"0"
""

will trigger a script to see that such folder is really empty regardless of whatever the user has instead of default "-".
Power-hungry user!!!

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: question on report of empty folders

Post by tiago »

No go with setting('BackgroundFileOps', 0);
It still doens't pops the warning.
Power-hungry user!!!

highend
Posts: 14954
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: question on report of empty folders

Post by highend »

What exactly are you trying to do, finding out (in a reliable way) if a folder is really empty?
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: question on report of empty folders

Post by tiago »

Yes.
Empty = no files at all inside (empty subfolders are allowed!). Zero-size files will report "0" as size and I need to match only folders which really have *nothing* inside them. But beware with those custom terms I'm 80% sure are lurking around...

My script will scan the current pane.

edit: there will be situations when empty subfolders will not be allowed so I'd like a note about it either.
Power-hungry user!!!

highend
Posts: 14954
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: question on report of empty folders

Post by highend »

Ok.

Code: Select all

	$checkforfiles = listfolder( , , 1);
	if($checkforfiles != "") {
		msg "damn, this folder has files inside";
	} else {
		msg "wow, no files at all here";
	}
This one should work. If the directory is empty (folders are allowed) the else will trigger.
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: question on report of empty folders

Post by tiago »

setting "ShowFolderSizeInList"; must be considered so your code does not apply, sorry for any confusion.

mm, hope you have the patience, let's try another way:

Code: Select all

<curpath>\Folder 1 - has empty files inside - allowed, will trigger

<curpath>\Folder 2 - has empty files and folders - allowed, will trigger

<curpath>\Folder 3 - has empty folders - allowed, will trigger

<curpath>\Folder 4 - has nothing - allowed, will trigger

<curpath>\Folder 5 - has files with size != 0 in any sublevel, not allowed, will not trigger
situation 2:

Code: Select all

<curpath>\Folder 1 - has empty files inside - NOT allowed, will NOT trigger

<curpath>\Folder 2 - has empty files and folders - NOT allowed, will NOT trigger

<curpath>\Folder 3 - has empty folders - NOT allowed, will NOT trigger

<curpath>\Folder 4 - has nothing - allowed, will trigger

<curpath>\Folder 5 - has files with size != 0 in any sublevel,  NOT allowed, will NOT trigger
situation 3:

Code: Select all

<curpath>\Folder 1 - has empty files inside - NOT allowed, will NOT trigger

<curpath>\Folder 2 - has empty files and folders - NOT allowed, will NOT trigger (because of empty files' rule)

<curpath>\Folder 3 - has empty folders - allowed, will trigger

<curpath>\Folder 4 - has nothing - allowed, will trigger

<curpath>\Folder 5 - has files with size != 0 in any sublevel, not allowed, will not trigger
situation 4:

Code: Select all

<curpath>\Folder 1 - has empty files inside - allowed, will trigger

<curpath>\Folder 2 - has empty files and folders - NOT allowed, will NOT trigger (because of empty folders' rule, next)

<curpath>\Folder 3 - has empty folders - NOT allowed, will NOT trigger

<curpath>\Folder 4 - has nothing - allowed, will trigger

<curpath>\Folder 5 - has files with size != 0 in any sublevel, not allowed, will not trigger
What I'm doing is extending a script of mine which currently deals with files only but now I must work on folders either and there's no general rule, that's why I'll have to implement parameters to each of those 4 situations I described. Thanks for the help, highend!
Power-hungry user!!!

highend
Posts: 14954
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: question on report of empty folders

Post by highend »

<curpath>\Folder 5 - has files with size != 0 in any sublevel, not allowed, will not trigger
Look at folderreport() to create a list of all files (with their folder) inside your current / destination dir; than a few regexes for your checks (of some kind of function -> Stefan's InStrRev (http://www.xyplorer.com/xyfc/viewtopic. ... t=instrrev))...

E.g. for a report:

Code: Select all

text folderreport("items:{dir {fullname}|{fullname} - {size b} |}", "r", , "r");
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: question on report of empty folders

Post by tiago »

Going nowhere with this.
Can someone please write a script which asks on which of the 4 situations to obey rules from, then pops a proper warning which later I'll convert into triggers?
Then I may finally finish my backup preparation script, currently working on files only.
Power-hungry user!!!

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: question on report of empty folders

Post by Stefan »

I don't have an good idea.

Perhaps this will help you as an hint:

Input:

Code: Select all

Folder 1 empty file
Folder 2 empty file and folder
Folder 3 empty folders
Folder 4 empty
Folder 5 files
Folder 6 files and folder

Script:

Code: Select all


  $Folders = get("SelectedItemsPathNames");
  foreach($fld, $Folders, "<crlf>"){
     if ($fld==""){break;}
     $FLDRS=""; $FILES="";

     //Get the size to see if any item, and if yes, how big:
     //needs listfolder() because folderreport() gives error on empty list:
      if (listfolder( $fld,,1) != ""){$FILES = folderreport("files:{size}", "r", $fld);}
      if (listfolder( $fld,,2) != ""){$FLDRS = folderreport("dirs: {size}", "r", $fld);}

     //remove line breaks from folderreport()
     //and drop the last signs, because we need only "yes" or "no", but nothing exactly:
      $FILES= substr( replace($FILES, "<crlf>", ""),0,4);
      $FLDRS= substr( replace($FLDRS, "<crlf>", ""),0,4);

     //generate the output:
      if ($FILES ==""){$fi=" NO ";}  elseif($FILES==0){$fi=" Yes, empty "}  else{$fi="Yes, non-empty";}
      if ($FLDRS ==""){$fo=" NO ";}  elseif($FLDRS==0){$fo=" Yes, empty "}  else{$fo="Yes, non-empty";}
      msg "$fld contains:<crlf>files: $fi<tab 2>$FILES<crlf>folders: $fo<tab>$FLDRS",1;
 }
Output:

Code: Select all

CurPath\Folder 1 empty file contains:
files:  Yes, empty 		0
folders:  NO 	


CurPath\Folder 2 empty file and folder contains:
files:  Yes, empty 		0
folders:  Yes, empty 	 0


CurPath\Folder 3 empty folders contains:
files:  NO
folders:  Yes, empty 	 0


CurPath\Folder 4 empty contains:
files:  NO
folders:  NO


CurPath\Folder 5 files contains:
files: Yes, non-empty		9626
folders:  NO


CurPath\Folder 6 files and folder contains:
files: Yes, non-empty		2320
folders: Yes, non-empty	 735
ToDo: get recursive report of size

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: question on report of empty folders

Post by tiago »

Initial tests went ok, Stefan. Recursive report seem to be already there as your script detects a file within a subfolder (C:\New Folder\New Folder 03 - 02\New Folder\_Links.txt), have to think on what else you may meant.

Thanks a bunch!
Power-hungry user!!!

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: question on report of empty folders

Post by Stefan »

tiago wrote: ... Recursive report seem to be already there ... have to think on what else you may meant.
Nothing special. I just had not the time to test all scenarios and thought recursive is missing.

Thanks for feedback.

Post Reply