├── .gitignore ├── Everything.cs ├── Everything64.dll ├── Program.cs ├── README.md └── everythingio.csproj /.gitignore: -------------------------------------------------------------------------------- 1 | /.vscode 2 | /bin 3 | /obj -------------------------------------------------------------------------------- /Everything.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | 7 | public static class Everything 8 | { 9 | #region API constants and references 10 | 11 | const int EVERYTHING_OK = 0; 12 | const int EVERYTHING_ERROR_MEMORY = 1; 13 | const int EVERYTHING_ERROR_IPC = 2; 14 | const int EVERYTHING_ERROR_REGISTERCLASSEX = 3; 15 | const int EVERYTHING_ERROR_CREATEWINDOW = 4; 16 | const int EVERYTHING_ERROR_CREATETHREAD = 5; 17 | const int EVERYTHING_ERROR_INVALIDINDEX = 6; 18 | const int EVERYTHING_ERROR_INVALIDCALL = 7; 19 | 20 | const int EVERYTHING_REQUEST_FILE_NAME = 0x00000001; 21 | const int EVERYTHING_REQUEST_PATH = 0x00000002; 22 | const int EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME = 0x00000004; 23 | const int EVERYTHING_REQUEST_EXTENSION = 0x00000008; 24 | const int EVERYTHING_REQUEST_SIZE = 0x00000010; 25 | const int EVERYTHING_REQUEST_DATE_CREATED = 0x00000020; 26 | const int EVERYTHING_REQUEST_DATE_MODIFIED = 0x00000040; 27 | const int EVERYTHING_REQUEST_DATE_ACCESSED = 0x00000080; 28 | const int EVERYTHING_REQUEST_ATTRIBUTES = 0x00000100; 29 | const int EVERYTHING_REQUEST_FILE_LIST_FILE_NAME = 0x00000200; 30 | const int EVERYTHING_REQUEST_RUN_COUNT = 0x00000400; 31 | const int EVERYTHING_REQUEST_DATE_RUN = 0x00000800; 32 | const int EVERYTHING_REQUEST_DATE_RECENTLY_CHANGED = 0x00001000; 33 | const int EVERYTHING_REQUEST_HIGHLIGHTED_FILE_NAME = 0x00002000; 34 | const int EVERYTHING_REQUEST_HIGHLIGHTED_PATH = 0x00004000; 35 | const int EVERYTHING_REQUEST_HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = 0x00008000; 36 | 37 | const int EVERYTHING_SORT_NAME_ASCENDING = 1; 38 | const int EVERYTHING_SORT_NAME_DESCENDING = 2; 39 | const int EVERYTHING_SORT_PATH_ASCENDING = 3; 40 | const int EVERYTHING_SORT_PATH_DESCENDING = 4; 41 | const int EVERYTHING_SORT_SIZE_ASCENDING = 5; 42 | const int EVERYTHING_SORT_SIZE_DESCENDING = 6; 43 | const int EVERYTHING_SORT_EXTENSION_ASCENDING = 7; 44 | const int EVERYTHING_SORT_EXTENSION_DESCENDING = 8; 45 | const int EVERYTHING_SORT_TYPE_NAME_ASCENDING = 9; 46 | const int EVERYTHING_SORT_TYPE_NAME_DESCENDING = 10; 47 | const int EVERYTHING_SORT_DATE_CREATED_ASCENDING = 11; 48 | const int EVERYTHING_SORT_DATE_CREATED_DESCENDING = 12; 49 | const int EVERYTHING_SORT_DATE_MODIFIED_ASCENDING = 13; 50 | const int EVERYTHING_SORT_DATE_MODIFIED_DESCENDING = 14; 51 | const int EVERYTHING_SORT_ATTRIBUTES_ASCENDING = 15; 52 | const int EVERYTHING_SORT_ATTRIBUTES_DESCENDING = 16; 53 | const int EVERYTHING_SORT_FILE_LIST_FILENAME_ASCENDING = 17; 54 | const int EVERYTHING_SORT_FILE_LIST_FILENAME_DESCENDING = 18; 55 | const int EVERYTHING_SORT_RUN_COUNT_ASCENDING = 19; 56 | const int EVERYTHING_SORT_RUN_COUNT_DESCENDING = 20; 57 | const int EVERYTHING_SORT_DATE_RECENTLY_CHANGED_ASCENDING = 21; 58 | const int EVERYTHING_SORT_DATE_RECENTLY_CHANGED_DESCENDING = 22; 59 | const int EVERYTHING_SORT_DATE_ACCESSED_ASCENDING = 23; 60 | const int EVERYTHING_SORT_DATE_ACCESSED_DESCENDING = 24; 61 | const int EVERYTHING_SORT_DATE_RUN_ASCENDING = 25; 62 | const int EVERYTHING_SORT_DATE_RUN_DESCENDING = 26; 63 | 64 | const int EVERYTHING_TARGET_MACHINE_X86 = 1; 65 | const int EVERYTHING_TARGET_MACHINE_X64 = 2; 66 | const int EVERYTHING_TARGET_MACHINE_ARM = 3; 67 | 68 | [DllImport("Everything64.dll", CharSet = CharSet.Unicode)] 69 | public static extern UInt32 Everything_SetSearchW(string lpSearchString); 70 | [DllImport("Everything64.dll")] 71 | public static extern void Everything_SetMatchPath(bool bEnable); 72 | [DllImport("Everything64.dll")] 73 | public static extern void Everything_SetMatchCase(bool bEnable); 74 | [DllImport("Everything64.dll")] 75 | public static extern void Everything_SetMatchWholeWord(bool bEnable); 76 | [DllImport("Everything64.dll")] 77 | public static extern void Everything_SetRegex(bool bEnable); 78 | [DllImport("Everything64.dll")] 79 | public static extern void Everything_SetMax(UInt32 dwMax); 80 | [DllImport("Everything64.dll")] 81 | public static extern void Everything_SetOffset(UInt32 dwOffset); 82 | 83 | [DllImport("Everything64.dll")] 84 | public static extern bool Everything_GetMatchPath(); 85 | [DllImport("Everything64.dll")] 86 | public static extern bool Everything_GetMatchCase(); 87 | [DllImport("Everything64.dll")] 88 | public static extern bool Everything_GetMatchWholeWord(); 89 | [DllImport("Everything64.dll")] 90 | public static extern bool Everything_GetRegex(); 91 | [DllImport("Everything64.dll")] 92 | public static extern UInt32 Everything_GetMax(); 93 | [DllImport("Everything64.dll")] 94 | public static extern UInt32 Everything_GetOffset(); 95 | [DllImport("Everything64.dll")] 96 | public static extern IntPtr Everything_GetSearchW(); 97 | [DllImport("Everything64.dll")] 98 | public static extern UInt32 Everything_GetLastError(); 99 | [DllImport("Everything64.dll")] 100 | public static extern bool Everything_QueryW(bool bWait); 101 | [DllImport("Everything64.dll")] 102 | public static extern void Everything_SortResultsByPath(); 103 | [DllImport("Everything64.dll")] 104 | public static extern UInt32 Everything_GetNumFileResults(); 105 | [DllImport("Everything64.dll")] 106 | public static extern UInt32 Everything_GetNumFolderResults(); 107 | [DllImport("Everything64.dll")] 108 | public static extern UInt32 Everything_GetNumResults(); 109 | [DllImport("Everything64.dll")] 110 | public static extern UInt32 Everything_GetTotFileResults(); 111 | [DllImport("Everything64.dll")] 112 | public static extern UInt32 Everything_GetTotFolderResults(); 113 | [DllImport("Everything64.dll")] 114 | public static extern UInt32 Everything_GetTotResults(); 115 | [DllImport("Everything64.dll")] 116 | public static extern bool Everything_IsVolumeResult(UInt32 nIndex); 117 | [DllImport("Everything64.dll")] 118 | public static extern bool Everything_IsFolderResult(UInt32 nIndex); 119 | [DllImport("Everything64.dll")] 120 | public static extern bool Everything_IsFileResult(UInt32 nIndex); 121 | [DllImport("Everything64.dll", CharSet = CharSet.Unicode)] 122 | public static extern void Everything_GetResultFullPathName(UInt32 nIndex, StringBuilder lpString, UInt32 nMaxCount); 123 | [DllImport("Everything64.dll")] 124 | public static extern void Everything_Reset(); 125 | [DllImport("Everything64.dll", CharSet = CharSet.Unicode)] 126 | public static extern IntPtr Everything_GetResultFileName(UInt32 nIndex); 127 | [DllImport("Everything64.dll")] 128 | public static extern void Everything_SetSort(UInt32 dwSortType); 129 | [DllImport("Everything64.dll")] 130 | public static extern UInt32 Everything_GetSort(); 131 | [DllImport("Everything64.dll")] 132 | public static extern UInt32 Everything_GetResultListSort(); 133 | [DllImport("Everything64.dll")] 134 | public static extern void Everything_SetRequestFlags(UInt32 dwRequestFlags); 135 | [DllImport("Everything64.dll")] 136 | public static extern UInt32 Everything_GetRequestFlags(); 137 | [DllImport("Everything64.dll")] 138 | public static extern UInt32 Everything_GetResultListRequestFlags(); 139 | [DllImport("Everything64.dll", CharSet = CharSet.Unicode)] 140 | public static extern IntPtr Everything_GetResultExtension(UInt32 nIndex); 141 | [DllImport("Everything64.dll")] 142 | public static extern bool Everything_GetResultSize(UInt32 nIndex, out long lpFileSize); 143 | [DllImport("Everything64.dll")] 144 | public static extern bool Everything_GetResultDateCreated(UInt32 nIndex, out long lpFileTime); 145 | [DllImport("Everything64.dll")] 146 | public static extern bool Everything_GetResultDateModified(UInt32 nIndex, out long lpFileTime); 147 | [DllImport("Everything64.dll")] 148 | public static extern bool Everything_GetResultDateAccessed(UInt32 nIndex, out long lpFileTime); 149 | [DllImport("Everything64.dll")] 150 | public static extern UInt32 Everything_GetResultAttributes(UInt32 nIndex); 151 | [DllImport("Everything64.dll", CharSet = CharSet.Unicode)] 152 | public static extern IntPtr Everything_GetResultFileListFileName(UInt32 nIndex); 153 | [DllImport("Everything64.dll")] 154 | public static extern UInt32 Everything_GetResultRunCount(UInt32 nIndex); 155 | [DllImport("Everything64.dll")] 156 | public static extern bool Everything_GetResultDateRun(UInt32 nIndex, out long lpFileTime); 157 | [DllImport("Everything64.dll")] 158 | public static extern bool Everything_GetResultDateRecentlyChanged(UInt32 nIndex, out long lpFileTime); 159 | [DllImport("Everything64.dll", CharSet = CharSet.Unicode)] 160 | public static extern IntPtr Everything_GetResultHighlightedFileName(UInt32 nIndex); 161 | [DllImport("Everything64.dll", CharSet = CharSet.Unicode)] 162 | public static extern IntPtr Everything_GetResultHighlightedPath(UInt32 nIndex); 163 | [DllImport("Everything64.dll", CharSet = CharSet.Unicode)] 164 | public static extern IntPtr Everything_GetResultHighlightedFullPathAndFileName(UInt32 nIndex); 165 | [DllImport("Everything64.dll")] 166 | public static extern UInt32 Everything_GetRunCountFromFileName(string lpFileName); 167 | [DllImport("Everything64.dll")] 168 | public static extern bool Everything_SetRunCountFromFileName(string lpFileName, UInt32 dwRunCount); 169 | [DllImport("Everything64.dll")] 170 | public static extern UInt32 Everything_IncRunCountFromFileName(string lpFileName); 171 | 172 | #endregion 173 | 174 | public static IEnumerable Search(string qry) 175 | { 176 | // set the search 177 | Everything_SetSearchW(qry); 178 | Everything_SetRequestFlags(EVERYTHING_REQUEST_FILE_NAME | EVERYTHING_REQUEST_PATH | EVERYTHING_REQUEST_DATE_MODIFIED | EVERYTHING_REQUEST_SIZE); 179 | 180 | // execute the query 181 | Everything_QueryW(true); 182 | var resultCount = Everything_GetNumResults(); 183 | 184 | // loop through the results, generating result objects 185 | for (uint i = 0; i < resultCount; i++) 186 | { 187 | var sb = new StringBuilder(999); 188 | Everything_GetResultFullPathName(i, sb, 999); 189 | Everything_GetResultDateModified(i, out long date_modified); 190 | Everything_GetResultSize(i, out long size); 191 | 192 | yield return new Result() { 193 | DateModified = DateTime.FromFileTime(date_modified), 194 | Size = size, 195 | Filename = Marshal.PtrToStringUni(Everything_GetResultFileName(i)), 196 | Path = sb.ToString() 197 | }; 198 | } 199 | } 200 | 201 | public struct Result 202 | { 203 | public long Size; //in bytes 204 | public DateTime DateModified; 205 | public string Filename; 206 | public string Path; 207 | 208 | public bool Folder => Size < 0; 209 | 210 | public override string ToString() 211 | => $"Name: {Filename}\tSize (B): {(Folder ? "(Folder)" : Size)}\tModified: {DateModified:d}\tPath: {Path.Substring(0, 15)}..."; 212 | } 213 | } -------------------------------------------------------------------------------- /Everything64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dipique/everythingio/429a580d6b23039a771fc5147299b0519bf5fe75/Everything64.dll -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | class Program 4 | { 5 | const int MAX_RESULTS = 20; 6 | static void Main(string[] args) 7 | { 8 | Console.WriteLine("Enter your search query:"); 9 | var qry = Console.ReadLine(); 10 | var results = Everything.Search(qry); 11 | 12 | var resultCount = 0; 13 | foreach(var result in results) 14 | { 15 | resultCount++; 16 | if (resultCount > MAX_RESULTS) 17 | break; 18 | 19 | Console.WriteLine($"{resultCount:D2}. {result.ToString()}"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Everything C# CLI Example 2 | 3 | CLI example of integrating the search capabilities of VoidTools Everything in C#. The logic is in a single static class that is compatible with both .Net Framework and .Net Core. Search results are provided by a non-greed iterator and each result is in an idiomatic class. 4 | 5 | This code may be used or or modified by anyone without payment or attribution as long as the purpose is legal. 6 | 7 | The Voidtools Everything code/software/api is not included in this "license"; please visit https://www.voidtools.com/ for more information. I think it's free but I am unaffiliated with the author and can't make statements on his behalf. 8 | 9 | If you feel generous, please donate to the creator of Everything: https://www.voidtools.com/donate/ 10 | -------------------------------------------------------------------------------- /everythingio.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | --------------------------------------------------------------------------------