windows file search wildcards and custom syntax

0

I'm developing tool for Windows SP0 and latter.

Now I need to add additional string in files and folders context menu, but there is a problem with folders.

To reach my goal I have created reg key HKEY_CLASSES_ROOT\Folder\shell\Add To File Shredder

I need to exclude Recycle Bin, My Computer and etc. so added value AppliesTo which is set to System.FileName:?*. It excludes most of folders I don't need, but some remains.

Now checking system and found that system drives fits this pattern, have found that their FileName is C:", D:" and etc.

There are two options how to exclude these paths:

  1. Check if last character is not ", regular files cannot have this so it is trusted.
  2. Check length of path. All paths have prefix, which shows drive letter, so this also is trusted.

However I don't know how to write search pattern which does one or another of these checks. Hope someone will help me.

Also, as I mentioned, I'm looking solution compatable with Win XP SP0 and latter.

Thanks!

ST3

Posted 2014-01-03T07:35:37.140

Reputation: 615

a minor nit pick.. what you call win xp sp0. there isn't an sp0, but it's clear what you mean, perhaps a better term is win xp (pre sp1). – barlop – 2014-01-03T07:42:41.363

@barlop I heard many "names" of that like no SP pre SP before SP and so on. Your criticism didn't hurt me however, I would be very glad if someone give me a link to msdn or something like it, where is written how this should be called. – ST3 – 2014-01-03T07:56:28.610

Pre sp1 isn't an official name or even a name. It's an english description pre meaning prior, that's why it's better to say it than sp0. Regarding Option 1 regex: (?!["]).$ <-- I tested that in regex buddy, it works. Though some programming languages may want you to do """ to escape a quote or some might want a ". I don't know if some regex versions want a ". but try that for the option 1 regex. – barlop – 2014-01-03T07:58:36.627

I am not sure why you want C:" (you suggest yourself earlier that filenames don't contain quotes and I guess that's right) but a regex for that would be ^[C-Z]:" possibly \" instead of ". That regex the ^ matches beginning of string. then a letter between C and Z. Then a colon then a quote. – barlop – 2014-01-03T08:04:10.867

It's probably safer to do your programming language's version of DIR, on the file. Just to see if it exists. Maybe the function you're using to get a list of files or folders, isn't good. You shouldn't have recycle bin in your list unless it's a proper path. – barlop – 2014-01-03T08:06:27.517

@barlop it is business with Windows shell, so regex cannot be used very widely. NOTE: " is illegal char in file names as it is used in special cases, like system drives termination sign, because it is possible (but painful) to have system drives that contains a few letters but is useless hacking. Also about DIR, it is partial solution, because it is better not to have button, then have button which does nothing. – ST3 – 2014-01-03T08:19:26.917

Do you mean you are writing this in batch? or vbscript? by the way, while it's true that vbscript doesn't have such good regex.. and it seems that's true of javascript or jscript too.. But I see somebody wrote " VBScript fully supports negative lookahead, does not support negative look behind (a significantly more complex and intensive behavior". So it should support that regex I wrote. As for DIR, I meant metaphorically i.e. using e.g. a vbscript function to list proper/valid files/folders. – barlop – 2014-01-03T08:45:31.183

As I mentioned, it is registry value. – ST3 – 2014-01-03T10:18:08.923

Have you tried something like 'System.FileName:?:??'. Although I thought you needed a tilda in there, e.g. 'System.FileName:~?:??' – snowdude – 2014-01-03T11:04:00.707

@snowdude well, ?:* sounds promising, however, it doesn't work... – ST3 – 2014-01-03T11:41:00.893

@ST3 ?:* is gibberish. Question mark has a special meaning in regex not like the cmd prompt. question mark doesn't mean 'any character'. And * doesn't mean some sequence of characters. regular expressions are not intuitive. To get a sequence of characters you need to write .* I gave you 2 regular expressions to try in a comment further up from this one. And you can test them. – barlop – 2014-01-03T17:21:27.393

No answers