-
Notifications
You must be signed in to change notification settings - Fork 1.6k
add missing examples for the EnumerateFiles method #11781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
StuartMosquera
wants to merge
9
commits into
dotnet:main
Choose a base branch
from
StuartMosquera:add-missing-examples-for-EnumerateFiles
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f9f1a1d
add missing examples for EnumerateFiles
StuartMosquera ed37a2d
add missing 'module' declaration to F# snippets
StuartMosquera cbd1b0d
add project file for C# & VB.NET
StuartMosquera 47d3a6a
fix type names conflicts
StuartMosquera 11de03c
update the target framework to 'net9.0'
StuartMosquera c061473
restore project file to 'net48'
StuartMosquera b09b6d2
update snippets location
StuartMosquera 2a24e76
update '.fsproj' files
StuartMosquera e405ec9
close snippet tag
StuartMosquera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
snippets/csharp/System.IO/Directory/EnumerateFiles/program3.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// <Snippet1> | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
partial class Example2 | ||
{ | ||
static void EnumerationOptionsExample() | ||
{ | ||
try | ||
{ | ||
// Set a variable to the My Documents path. | ||
string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); | ||
|
||
// Set the options for the enumeration. | ||
var options = new EnumerationOptions | ||
{ | ||
IgnoreInaccessible = true, | ||
MatchCasing = MatchCasing.CaseInsensitive, | ||
MatchType = MatchType.Simple, | ||
RecurseSubdirectories = true | ||
}; | ||
|
||
var files = from file in Directory.EnumerateFiles(docPath, "*.txt", options) | ||
from line in File.ReadLines(file) | ||
where line.Contains("Microsoft") | ||
select new | ||
{ | ||
File = file, | ||
Line = line | ||
}; | ||
|
||
foreach (var f in files) | ||
{ | ||
Console.WriteLine($"{f.File}\t{f.Line}"); | ||
} | ||
|
||
Console.WriteLine($"{files.Count()} files found."); | ||
} | ||
catch (PathTooLongException pathEx) | ||
{ | ||
Console.WriteLine(pathEx.Message); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex.Message); | ||
} | ||
} | ||
} | ||
// </Snippet1> |
8 changes: 8 additions & 0 deletions
8
snippets/csharp/System.IO/Directory/EnumerateFiles/project.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @gewarren, this code is legacy, right? The second parameter of the
CreateDirectory
method is only for Unix-like systems, or am I wrong?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looks like the 2-parameter overload takes a DirectorySecurity in .NET Framework and a UnixFileMode in .NET. So this project will need to target .NET Framework instead of .NET 9 since this example is used in the .NET Framework overload docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, Thanks!