diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1c8faeb --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/net5.0/files-module.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..4f923f1 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/files-module.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/files-module.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/files-module.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..3e83d82 --- /dev/null +++ b/Program.cs @@ -0,0 +1,45 @@ +using System; +using System.IO; +using System.Collections.Generic; + +namespace files_module +{ + class Program + { + static void Main(string[] args) + { + // Pass in the name of the folder "stores" to the FindFiles method + var salesFiles = FindFiles("stores"); + + // For each file that matched the search criteria in the FindFiles method + // it was added to "salesFile" - and we now print each filename and its location + foreach (var file in salesFiles) + { + Console.WriteLine(file); + } + } + + // Create a new function called FindFiles that takes a folderName parameter. + static IEnumerable FindFiles(string folderName) + { + // Create a new list of type strings named "salesFiles" + List salesFiles = new List(); + + // Searches the directory location specified and returns the full file names + // and the relevant file paths + var foundFiles = Directory.EnumerateFiles(folderName, "*", SearchOption.AllDirectories); + + // Search and check each file in "foundFiles" against parameter + foreach (var file in foundFiles) + { + // The file name will contain the full path so only check the end of it and if a match + // add this file to "salesFile" + if (file.EndsWith("sales.json")) + { + salesFiles.Add(file); + } + } + return salesFiles; // Return the contents of "salesfile" to memory + }//findFiles + }//Program +}//files_module diff --git a/files-module.csproj b/files-module.csproj new file mode 100644 index 0000000..f120ba8 --- /dev/null +++ b/files-module.csproj @@ -0,0 +1,9 @@ + + + + Exe + net5.0 + files_module + + +