How to check a file if exists with wildcard in Java?

Pass a FileFilter (coded here anonymously) into the listFiles() method of the dir File, like this: File dir = new File(“some/path/to/dir”); final String id = “XXX”; // needs to be final so the anonymous class can use it File[] matchingFiles = dir.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.getName().equals(“a_id_” + id + “.zip”); … Read more

When to use wildcards in Java Generics?

The big difference between public <T extends Animal> void takeThing(ArrayList<T> list) and public void takeThing(ArrayList<? extends Animal> list) is that in the former method you can refer to “T” within the method as the concrete class that was given. In the second method you cannot do this. Here a more complex example to illustrate this: … Read more

“like” queries in Entity Framework

This guy made a very nice “WhereLike” extension for Linq that accepts any wildcard character and compares two values (one of which comes from an expression) with a generic method derived from the location of the wildcard. x% -> startswith %x -> endswith %x% -> contains http://trentacular.com/2010/08/linq-to-entities-wild-card-like-extension-method/ EDIT: The article seems to be down. I … Read more

How to implement glob in C#

/// <summary> /// return a list of files that matches some wildcard pattern, e.g. /// C:\p4\software\dotnet\tools\*\*.sln to get all tool solution files /// </summary> /// <param name=”glob”>pattern to match</param> /// <returns>all matching paths</returns> public static IEnumerable<string> Glob(string glob) { foreach (string path in Glob(PathHead(glob) + DirSep, PathTail(glob))) yield return path; } /// <summary> /// uses … Read more

Using a wildcard to open an excel workbook

We cannot open a file using a wildcard – imagine the chaos if we could! You’ll need to use Dir(ActiveWorkbook.Path & “\302113*.xlsm”) to loop through the files that this returns. If there will only be one then just use this function once: Dim sFound As String sFound = Dir(ActiveWorkbook.Path & “\302113*.xlsm”) ‘the first one found … Read more

Is it possible to use a CSS wildcard in the middle of an attribute selector?

You can’t use a wildcard like that, but to get the desired result (ID starts with lorem and ends with Ipsum) you can use the attribute starts-with and ends-with selectors instead, like so: p[id^=”lorem”][id$=”Ipsum”] Remember that by linking multiple attribute selectors like this (along with the p type selector), you’re doing an AND match with … Read more

Rename multiple files in cmd

Make sure that there are more ? than there are characters in the longest name: ren *.txt “???????????????????????????? 1.1.txt” See How does the Windows RENAME command interpret wildcards? for more info. New Solution – 2014/12/01 For those who like regular expressions, there is JREN.BAT – a hybrid JScript/batch command line utility that will run on … Read more