Get all Files and Folders in a Folder [duplicate]What is the difference between EnumerateFiles and EnumerateFileSystemEntries in .NET 4?How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Retrieving Property name from lambda expressionGet int value from enum in C#How to loop through all enum values in C#?How to delete all files and folders in a directory?Get all files and directories in specific path fastGet current folder pathd is less efficient than [0-9]Why not inherit from List<T>?
Why is it called stateful and stateless firewall?
Why is the year in this ISO timestamp not 2019?
Is there any reason to concentrate on the Thunderous Smite spell after using its effects?
Can a character with good/neutral alignment attune to a sentient magic item with evil alignment?
Should you only use colons and periods in dialogues?
Amortized Loans seem to benefit the bank more than the customer
In what state are satellites left in when they are left in a graveyard orbit?
What 68-pin connector is this on my 2.5" solid state drive?
What is a "major country" as named in Bernie Sanders' Healthcare debate answers?
In what sequence should an advanced civilization teach technology to medieval society to maximize rate of adoption?
Shouldn't countries like Russia and Canada support global warming?
Make 2019 with single digits
Why are some files not movable on Windows 10?
What was the motivation for the invention of electric pianos?
Where is it? - The Google Earth Challenge Ep. 3
2000s space film where an alien species has almost wiped out the human race in a war
Exponentiation with parentheses
Bit one of the Intel 8080's Flags register
Would it be unbalanced to increase a druid's number of uses of Wild Shape based on level?
How do certain apps show new notifications when internet access is restricted to them?
Can I travel to European countries with the Irish passport and without destination Visa?
What organs or modifications would be needed for a life biological creature not to require sleep?
Isometries of convex hypersurfaces
Is there a tool to measure the "maturity" of a code in Git?
Get all Files and Folders in a Folder [duplicate]
What is the difference between EnumerateFiles and EnumerateFileSystemEntries in .NET 4?How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?Retrieving Property name from lambda expressionGet int value from enum in C#How to loop through all enum values in C#?How to delete all files and folders in a directory?Get all files and directories in specific path fastGet current folder pathd is less efficient than [0-9]Why not inherit from List<T>?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
This question already has an answer here:
What is the difference between EnumerateFiles and EnumerateFileSystemEntries in .NET 4?
3 answers
Currently i use this to get all files in a folder:
IEnumerable<string> files;
files = Directory.EnumerateFiles(datapath, "*", SearchOption.AllDirectories);
where datapath is just a string with the folder path.
With this i get all files and also the folders that contain files, but if i have empty folders i don't get them.
I thought about using Directory.EnumerateDirectories but than i would have all directories, even those that where already found by Directory.EnumerateFiles
Is there a better way to handle this?
c#
marked as duplicate by aloisdg, Mong Zhu, mjwills, Md. Suman Kabir, stuartd
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 28 at 12:45
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment
|
This question already has an answer here:
What is the difference between EnumerateFiles and EnumerateFileSystemEntries in .NET 4?
3 answers
Currently i use this to get all files in a folder:
IEnumerable<string> files;
files = Directory.EnumerateFiles(datapath, "*", SearchOption.AllDirectories);
where datapath is just a string with the folder path.
With this i get all files and also the folders that contain files, but if i have empty folders i don't get them.
I thought about using Directory.EnumerateDirectories but than i would have all directories, even those that where already found by Directory.EnumerateFiles
Is there a better way to handle this?
c#
marked as duplicate by aloisdg, Mong Zhu, mjwills, Md. Suman Kabir, stuartd
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 28 at 12:45
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You can try something like this: Loop through your IEnumerable and do:var folder = new DirectoryInfo(path); if (folder.Exists) return folder.GetFileSystemInfos().Length == 0;
– Joel
Mar 28 at 12:10
3
EnumerateFilesenumerates files, not dictionaries. The method that enumerates both isEnumerateFileSystemEntries
– Panagiotis Kanavos
Mar 28 at 12:12
@JoelGetFileSystemInfos()will return only after all results are found. It's better to use theEnumerate...methods. In any case that snippet doesn't do what the OP asked, it only checks whether the root folder is empty or not, in a rather expensive way.EnumerateFileSystemInfos().Any()would do the same but return immediatelly
– Panagiotis Kanavos
Mar 28 at 12:15
@AlpakaJoe This is a good question. You are not the only one to face this issue. Please close your question and see my answer here.
– aloisdg
Mar 28 at 12:22
add a comment
|
This question already has an answer here:
What is the difference between EnumerateFiles and EnumerateFileSystemEntries in .NET 4?
3 answers
Currently i use this to get all files in a folder:
IEnumerable<string> files;
files = Directory.EnumerateFiles(datapath, "*", SearchOption.AllDirectories);
where datapath is just a string with the folder path.
With this i get all files and also the folders that contain files, but if i have empty folders i don't get them.
I thought about using Directory.EnumerateDirectories but than i would have all directories, even those that where already found by Directory.EnumerateFiles
Is there a better way to handle this?
c#
This question already has an answer here:
What is the difference between EnumerateFiles and EnumerateFileSystemEntries in .NET 4?
3 answers
Currently i use this to get all files in a folder:
IEnumerable<string> files;
files = Directory.EnumerateFiles(datapath, "*", SearchOption.AllDirectories);
where datapath is just a string with the folder path.
With this i get all files and also the folders that contain files, but if i have empty folders i don't get them.
I thought about using Directory.EnumerateDirectories but than i would have all directories, even those that where already found by Directory.EnumerateFiles
Is there a better way to handle this?
This question already has an answer here:
What is the difference between EnumerateFiles and EnumerateFileSystemEntries in .NET 4?
3 answers
c#
c#
edited Mar 28 at 12:24
Diado
1,5952 gold badges12 silver badges16 bronze badges
1,5952 gold badges12 silver badges16 bronze badges
asked Mar 28 at 12:06
AlpakaJoeAlpakaJoe
1809 bronze badges
1809 bronze badges
marked as duplicate by aloisdg, Mong Zhu, mjwills, Md. Suman Kabir, stuartd
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 28 at 12:45
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by aloisdg, Mong Zhu, mjwills, Md. Suman Kabir, stuartd
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 28 at 12:45
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by aloisdg, Mong Zhu, mjwills, Md. Suman Kabir, stuartd
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 28 at 12:45
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You can try something like this: Loop through your IEnumerable and do:var folder = new DirectoryInfo(path); if (folder.Exists) return folder.GetFileSystemInfos().Length == 0;
– Joel
Mar 28 at 12:10
3
EnumerateFilesenumerates files, not dictionaries. The method that enumerates both isEnumerateFileSystemEntries
– Panagiotis Kanavos
Mar 28 at 12:12
@JoelGetFileSystemInfos()will return only after all results are found. It's better to use theEnumerate...methods. In any case that snippet doesn't do what the OP asked, it only checks whether the root folder is empty or not, in a rather expensive way.EnumerateFileSystemInfos().Any()would do the same but return immediatelly
– Panagiotis Kanavos
Mar 28 at 12:15
@AlpakaJoe This is a good question. You are not the only one to face this issue. Please close your question and see my answer here.
– aloisdg
Mar 28 at 12:22
add a comment
|
You can try something like this: Loop through your IEnumerable and do:var folder = new DirectoryInfo(path); if (folder.Exists) return folder.GetFileSystemInfos().Length == 0;
– Joel
Mar 28 at 12:10
3
EnumerateFilesenumerates files, not dictionaries. The method that enumerates both isEnumerateFileSystemEntries
– Panagiotis Kanavos
Mar 28 at 12:12
@JoelGetFileSystemInfos()will return only after all results are found. It's better to use theEnumerate...methods. In any case that snippet doesn't do what the OP asked, it only checks whether the root folder is empty or not, in a rather expensive way.EnumerateFileSystemInfos().Any()would do the same but return immediatelly
– Panagiotis Kanavos
Mar 28 at 12:15
@AlpakaJoe This is a good question. You are not the only one to face this issue. Please close your question and see my answer here.
– aloisdg
Mar 28 at 12:22
You can try something like this: Loop through your IEnumerable and do:
var folder = new DirectoryInfo(path); if (folder.Exists) return folder.GetFileSystemInfos().Length == 0; – Joel
Mar 28 at 12:10
You can try something like this: Loop through your IEnumerable and do:
var folder = new DirectoryInfo(path); if (folder.Exists) return folder.GetFileSystemInfos().Length == 0; – Joel
Mar 28 at 12:10
3
3
EnumerateFiles enumerates files, not dictionaries. The method that enumerates both is EnumerateFileSystemEntries– Panagiotis Kanavos
Mar 28 at 12:12
EnumerateFiles enumerates files, not dictionaries. The method that enumerates both is EnumerateFileSystemEntries– Panagiotis Kanavos
Mar 28 at 12:12
@Joel
GetFileSystemInfos() will return only after all results are found. It's better to use the Enumerate... methods. In any case that snippet doesn't do what the OP asked, it only checks whether the root folder is empty or not, in a rather expensive way. EnumerateFileSystemInfos().Any() would do the same but return immediatelly– Panagiotis Kanavos
Mar 28 at 12:15
@Joel
GetFileSystemInfos() will return only after all results are found. It's better to use the Enumerate... methods. In any case that snippet doesn't do what the OP asked, it only checks whether the root folder is empty or not, in a rather expensive way. EnumerateFileSystemInfos().Any() would do the same but return immediatelly– Panagiotis Kanavos
Mar 28 at 12:15
@AlpakaJoe This is a good question. You are not the only one to face this issue. Please close your question and see my answer here.
– aloisdg
Mar 28 at 12:22
@AlpakaJoe This is a good question. You are not the only one to face this issue. Please close your question and see my answer here.
– aloisdg
Mar 28 at 12:22
add a comment
|
2 Answers
2
active
oldest
votes
The method that returns both directories and files is Directory.EnumerateFileSystemEntries
Avoid to post link only answer.
– aloisdg
Mar 28 at 12:11
stackoverflow.com/a/13451748/2902996
– Joel
Mar 28 at 12:13
@aoisdg the method that returns both directories and files isEnumerateFileSystemEntries. This isn't a link-only question, it's the exact question with a link to the docs. Yes, adding 6 more words would make it better, but this is the answer
– Panagiotis Kanavos
Mar 28 at 12:13
@Joel that link says the same as this question
– Panagiotis Kanavos
Mar 28 at 12:14
2
Now it does that. Previously your answer was "Have a look at Directory.EnumerateFileSystemEntries method here". Which doesn't state anything really.
– Joel
Mar 28 at 12:16
|
show 2 more comments
You should use Directory.GetDirectories and then for each folder and file you can ran foreach loop. You can read more about this solution here http://www.csharp411.com/c-copy-folder-recursively/
This is too complicated when you have a simpler handy solution. Check the duplicate question here.
– aloisdg
Mar 28 at 12:23
add a comment
|
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The method that returns both directories and files is Directory.EnumerateFileSystemEntries
Avoid to post link only answer.
– aloisdg
Mar 28 at 12:11
stackoverflow.com/a/13451748/2902996
– Joel
Mar 28 at 12:13
@aoisdg the method that returns both directories and files isEnumerateFileSystemEntries. This isn't a link-only question, it's the exact question with a link to the docs. Yes, adding 6 more words would make it better, but this is the answer
– Panagiotis Kanavos
Mar 28 at 12:13
@Joel that link says the same as this question
– Panagiotis Kanavos
Mar 28 at 12:14
2
Now it does that. Previously your answer was "Have a look at Directory.EnumerateFileSystemEntries method here". Which doesn't state anything really.
– Joel
Mar 28 at 12:16
|
show 2 more comments
The method that returns both directories and files is Directory.EnumerateFileSystemEntries
Avoid to post link only answer.
– aloisdg
Mar 28 at 12:11
stackoverflow.com/a/13451748/2902996
– Joel
Mar 28 at 12:13
@aoisdg the method that returns both directories and files isEnumerateFileSystemEntries. This isn't a link-only question, it's the exact question with a link to the docs. Yes, adding 6 more words would make it better, but this is the answer
– Panagiotis Kanavos
Mar 28 at 12:13
@Joel that link says the same as this question
– Panagiotis Kanavos
Mar 28 at 12:14
2
Now it does that. Previously your answer was "Have a look at Directory.EnumerateFileSystemEntries method here". Which doesn't state anything really.
– Joel
Mar 28 at 12:16
|
show 2 more comments
The method that returns both directories and files is Directory.EnumerateFileSystemEntries
The method that returns both directories and files is Directory.EnumerateFileSystemEntries
edited Mar 28 at 12:14
Panagiotis Kanavos
63.7k6 gold badges91 silver badges124 bronze badges
63.7k6 gold badges91 silver badges124 bronze badges
answered Mar 28 at 12:10
Pavel AnikhouskiPavel Anikhouski
1,7653 gold badges12 silver badges19 bronze badges
1,7653 gold badges12 silver badges19 bronze badges
Avoid to post link only answer.
– aloisdg
Mar 28 at 12:11
stackoverflow.com/a/13451748/2902996
– Joel
Mar 28 at 12:13
@aoisdg the method that returns both directories and files isEnumerateFileSystemEntries. This isn't a link-only question, it's the exact question with a link to the docs. Yes, adding 6 more words would make it better, but this is the answer
– Panagiotis Kanavos
Mar 28 at 12:13
@Joel that link says the same as this question
– Panagiotis Kanavos
Mar 28 at 12:14
2
Now it does that. Previously your answer was "Have a look at Directory.EnumerateFileSystemEntries method here". Which doesn't state anything really.
– Joel
Mar 28 at 12:16
|
show 2 more comments
Avoid to post link only answer.
– aloisdg
Mar 28 at 12:11
stackoverflow.com/a/13451748/2902996
– Joel
Mar 28 at 12:13
@aoisdg the method that returns both directories and files isEnumerateFileSystemEntries. This isn't a link-only question, it's the exact question with a link to the docs. Yes, adding 6 more words would make it better, but this is the answer
– Panagiotis Kanavos
Mar 28 at 12:13
@Joel that link says the same as this question
– Panagiotis Kanavos
Mar 28 at 12:14
2
Now it does that. Previously your answer was "Have a look at Directory.EnumerateFileSystemEntries method here". Which doesn't state anything really.
– Joel
Mar 28 at 12:16
Avoid to post link only answer.
– aloisdg
Mar 28 at 12:11
Avoid to post link only answer.
– aloisdg
Mar 28 at 12:11
stackoverflow.com/a/13451748/2902996
– Joel
Mar 28 at 12:13
stackoverflow.com/a/13451748/2902996
– Joel
Mar 28 at 12:13
@aoisdg the method that returns both directories and files is
EnumerateFileSystemEntries. This isn't a link-only question, it's the exact question with a link to the docs. Yes, adding 6 more words would make it better, but this is the answer– Panagiotis Kanavos
Mar 28 at 12:13
@aoisdg the method that returns both directories and files is
EnumerateFileSystemEntries. This isn't a link-only question, it's the exact question with a link to the docs. Yes, adding 6 more words would make it better, but this is the answer– Panagiotis Kanavos
Mar 28 at 12:13
@Joel that link says the same as this question
– Panagiotis Kanavos
Mar 28 at 12:14
@Joel that link says the same as this question
– Panagiotis Kanavos
Mar 28 at 12:14
2
2
Now it does that. Previously your answer was "Have a look at Directory.EnumerateFileSystemEntries method here". Which doesn't state anything really.
– Joel
Mar 28 at 12:16
Now it does that. Previously your answer was "Have a look at Directory.EnumerateFileSystemEntries method here". Which doesn't state anything really.
– Joel
Mar 28 at 12:16
|
show 2 more comments
You should use Directory.GetDirectories and then for each folder and file you can ran foreach loop. You can read more about this solution here http://www.csharp411.com/c-copy-folder-recursively/
This is too complicated when you have a simpler handy solution. Check the duplicate question here.
– aloisdg
Mar 28 at 12:23
add a comment
|
You should use Directory.GetDirectories and then for each folder and file you can ran foreach loop. You can read more about this solution here http://www.csharp411.com/c-copy-folder-recursively/
This is too complicated when you have a simpler handy solution. Check the duplicate question here.
– aloisdg
Mar 28 at 12:23
add a comment
|
You should use Directory.GetDirectories and then for each folder and file you can ran foreach loop. You can read more about this solution here http://www.csharp411.com/c-copy-folder-recursively/
You should use Directory.GetDirectories and then for each folder and file you can ran foreach loop. You can read more about this solution here http://www.csharp411.com/c-copy-folder-recursively/
answered Mar 28 at 12:22
Aleksander ZawiszaAleksander Zawisza
375 bronze badges
375 bronze badges
This is too complicated when you have a simpler handy solution. Check the duplicate question here.
– aloisdg
Mar 28 at 12:23
add a comment
|
This is too complicated when you have a simpler handy solution. Check the duplicate question here.
– aloisdg
Mar 28 at 12:23
This is too complicated when you have a simpler handy solution. Check the duplicate question here.
– aloisdg
Mar 28 at 12:23
This is too complicated when you have a simpler handy solution. Check the duplicate question here.
– aloisdg
Mar 28 at 12:23
add a comment
|
You can try something like this: Loop through your IEnumerable and do:
var folder = new DirectoryInfo(path); if (folder.Exists) return folder.GetFileSystemInfos().Length == 0;– Joel
Mar 28 at 12:10
3
EnumerateFilesenumerates files, not dictionaries. The method that enumerates both isEnumerateFileSystemEntries– Panagiotis Kanavos
Mar 28 at 12:12
@Joel
GetFileSystemInfos()will return only after all results are found. It's better to use theEnumerate...methods. In any case that snippet doesn't do what the OP asked, it only checks whether the root folder is empty or not, in a rather expensive way.EnumerateFileSystemInfos().Any()would do the same but return immediatelly– Panagiotis Kanavos
Mar 28 at 12:15
@AlpakaJoe This is a good question. You are not the only one to face this issue. Please close your question and see my answer here.
– aloisdg
Mar 28 at 12:22