2

I have a question about searching for files in Windows Server 2008 R2. We are automating Excel (don't ask) which when fails can leave behind the temporary files that have an extension of .XLS~

If I do a manual search for *.xls~ it appears that Server 2008 is treating the tilde as a wildcard and returning ALL *.xls files, which of course is not what I want.

Can anyone please tell me how I can do this search so it will bring back the correct files? Is there an escape character I can use? Someone told me to use double quotes and try searching for *."xls~" but that doesn't work.

Muzzman
  • 21
  • 1
  • 3

3 Answers3

4

The "~" character is an operator in the Advanced Query Syntax used by Windows Search.

By itself, it indicates that a search contains wildcards, as in System.FileName:~"Mic?osoft W*d" matching a filename Microsoft Word.

To literally match the "*.xls~" filename you would search for System.Filename:~"*.xls~"

My old, less-well-informed answer, which I am only keeping around because of the novelty of piping to the clipboard, this:

I'd throw open a command prompt and do a dir /b /s/a x:\*.xls~ (substituting in the appropriate drive letter). If you want the list on the clipboard add a | clip to the command. You won't get your files in a pretty Explorer view, but you will get a list.

If you want to do that w/o leaving your GUI just open the "Run" box and put in cmd /c dir /s /a /b x:\*.xls~ | clip and, after the cmd.exe window closes you'll have your results on the clipboard.

Evan Anderson
  • 141,881
  • 20
  • 196
  • 331
  • I don't know why but that's the first time I've ever seen a command piped straight to the clipboard. Thanks for the tip. – John Gardeniers Mar 11 '11 at 04:22
  • @John Gardeniers: I find myself, fairly regularly, running `cmd /c xxxx` commands from the GUI. If I need to make a directory somewhere, copy some files, etc, that's what I'll do if I don't already have a shell open somewhere. Typing `cmd /c ` is very quick... >smile – Evan Anderson Mar 11 '11 at 13:07
  • In windows explorer search, ~ is an operator. If you write "~foo" it means more or less "matches foo". For example, to search for a filename that contains a ~, you have to write `file:~"*~*"` - also note that the 'file' is localized, so for example I have to write `plik:~"*~*"` – quetzalcoatl Feb 14 '19 at 12:08
  • Ahh... a "feature", as I suspected. Thanks for the explanation. – Evan Anderson Feb 14 '19 at 21:54
1

Assuming you're talking about Windows Search, try ~*".xls~" This also helps with parentheses, e.g. ~*"(1).xls"

Mark Sowul
  • 1,839
  • 1
  • 11
  • 14
0

~ is not a wildcard in PowerShell, so:

dir startingPath -recurse -filter '*.xls~'
Richard
  • 5,324
  • 1
  • 23
  • 20