Snippet Request - sc listfolder exceptions

Discuss and share scripts and script files...
Post Reply
SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Snippet Request - sc listfolder exceptions

Post by SkyFrontier »

Hi, guyz.

sc listfolder, despite help file saying 'recycle bin' is not supported, seems to have other limitations - a lot of places under 'user', for instance. Also, this certainly varies according to the host OS under which the script is run.
I'm not willing to restart XY instances under certain privileges or anything in that direction...
So, can someone please provide a method that detects and skips those places, hopefuly returning some useful info?
Thanks in advance.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Snippet Request - sc listfolder exceptions

Post by highend »

Can you a bit more specific on what exactly is listed through listfolder() and what would need to be filtered?

E.g. to return the content of %USERPROFILE% without any junctions stuff in it, you could do it like this:

Code: Select all

    text reportfolders("%USERPROFILE%");

function reportfolders($path, $sep=<crlf>) {
    $items = report("{fullname}{Dir \}|{prop:#JunctionTarget}<crlf>", listfolder($path));
    $items = regexreplace($items, "^[^|]+\\\|([a-z]|\\\\).*");
    $items = regexreplace($items, "\|.*?(?=\r?\n|$)");
    $folders = formatlist(regexmatches($items, ".*\\$", $sep), "s", $sep);
    $files   = formatlist($items, "f", $sep, "!$folders");
    return formatlist($folders . $sep . $files, "e", $sep);
}
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Snippet Request - sc listfolder exceptions

Post by SkyFrontier »

Hello, highend.
That's the point: I'm trying to find a way for listfolder to fail silently WITHOUT a generic flag, so I could inform the user that folder X is not accessible because it is hosted on OS Y (which may not happen on other win versions), as those 'black listed' folders could be indexed anywhere I'm unable to find in such a generic way.

As a last resort I could use flag '32'\ReturnCount if it was == "", but... listfolder fails before that, too.

:cry:

Thanks!
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Snippet Request - sc listfolder exceptions

Post by SkyFrontier »

Tested your code, yes, it's a start...
But: is there a fast way to retrieve those folders on the entire system, so I could check inputs against this black list prior to sending a target to listfolder?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Snippet Request - sc listfolder exceptions

Post by highend »

to retrieve those folders on the entire system
Which folders should that be (apart from e.g. user shell folders (which are in the registry))?
Examples...
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Snippet Request - sc listfolder exceptions

Post by SkyFrontier »

I'll have to poll them from real usage, then, as until today I really didn't care about them seriously due to lack of time to try to fix this.

Examples of false positives in quick tests:

C:\Users\%user%\.anyvid
C:\Users\%user%\.cache
C:\Users\%user%\.cream
C:\Users\%user%\.ebookreader
-can this be a hint that an official 'skip' flag is needed, here...?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Snippet Request - sc listfolder exceptions

Post by highend »

So they aren't an windows specific ones, e.g. virtual folders

Just create a check() function, with e.g. a heredoc that contains these patterns/folders and check against them
or just filter them out via formatlist()...
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Snippet Request - sc listfolder exceptions

Post by SkyFrontier »

Hmmm...
Lets try another way:

I have a distant memory that there were a script command capable of silently fail at recycle bin and sys volume info, for instance, which also were capable of providing a basic return. I could use it before recurring to listfolder, I guess.

-which sc were that one...?
-could you please provide a fast method to check an entire drive and retrieve those 'forbidden access' folders, then?
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Snippet Request - sc listfolder exceptions

Post by highend »

-which sc were that one...?
I'm not aware of any sc that "silently" fails on specific folders (by trying to access them?). Which doesn't mean that it exists but I've never used it then...
-could you please provide a fast method to check an entire drive and retrieve those 'forbidden access' folders, then?
What do you mean by "retrieving" them? The input to that function is a drive (letter), ok.
And then?

Are we talking about finding
$REYCLE.BIN
System Volume Information
%user%\.anyvid
...
and returning the list of these folders on that specific drive?
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Snippet Request - sc listfolder exceptions

Post by SkyFrontier »

highend wrote:I'm not aware of any sc that "silently" fails on specific folders (by trying to access them?)
It's been a while I'm away of coding, so it's hard to tell actual examples of stuf that used to pop XY script dialog with error messages that later were converted into gentle return codes, sorry if I'm causing you trouble here.
highend wrote:
What do you mean by "retrieving" them? The input to that function is a drive (letter), ok.
Polling a drive in search for those folders that thow XY script error window with "acesso negado" ('forbidden access') messages...
A live list of those would be more reliable and portable than a hard-coded one, then I'd do what you suggested with the function thing (ie, traversing that list against my input, thus avoiding listfolder to hit them and popping those error messages).

Sorry for some delay, I'm on other stuff here, too. But I'll notify if\when have to leave...
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Snippet Request - sc listfolder exceptions

Post by SkyFrontier »

By the way,
%user%\.anyvid
and the likes are false positives on your first guess of the problem.
The focus is stuff like recycle bin and system volume information, which pops the XY error messages when listfolder'ed.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Snippet Request - sc listfolder exceptions

Post by SkyFrontier »

Stuff in the likes I had in mind when talking about 'silent' operations:

readurl(), [flag 2] - silent mode (no error messages) ((this is a more exact example))
copyas, [targetpath] - The path is silently auto-created if it does not exist. (('move\copyto'\flag 2, 'copyitem' and others, too))

There may be more, but you've got the picture.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Snippet Request - sc listfolder exceptions

Post by highend »

report() doesn't support it. returning 0 for zero subfolders says nothing about if a folder is non accessible because of missing permissions
checking for attributes (e.g. HSD) doesn't cut is as well

So atm: At least not as far as I know...

A list put on a web server where the check functions accesses it and checks it against the given path would be a possibility
It wouldn't require updates for the script on the clients but ofc they'd need i-net access

Checking DACLs of folders against your own (user / group)... Possible but requires external stuff

I'd request an additional pattern for the template part of report or if you only need it for the listfolder function a way to give back a result like -1 if the folder is not accessible
One of my scripts helped you out? Please donate via Paypal

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Snippet Request - sc listfolder exceptions

Post by SkyFrontier »

I've tried something like
echo exists(<curitem> . "\");
on top of those referenced folders, having '2' as a result. Which is kind of expected anyway, since they are... folders, after all. :(
I'll take a (careful) look at the report() suggestion, tho. I'm avoiding a new flag because of backwards compatibility (down to 16.80, if possible).

Thanks much, highend. You're gold.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Post Reply