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;








2
















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?










share|improve this question
















marked as duplicate by aloisdg, Mong Zhu, mjwills, Md. Suman Kabir, stuartd c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

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





    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












  • @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

















2
















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?










share|improve this question
















marked as duplicate by aloisdg, Mong Zhu, mjwills, Md. Suman Kabir, stuartd c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

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





    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












  • @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













2












2








2









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?










share|improve this question

















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#






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

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 c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

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 c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

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





    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












  • @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







  • 3





    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












  • @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












2 Answers
2






active

oldest

votes


















0
















The method that returns both directories and files is Directory.EnumerateFileSystemEntries






share|improve this answer



























  • 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 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






  • 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


















0
















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/






share|improve this answer

























  • This is too complicated when you have a simpler handy solution. Check the duplicate question here.

    – aloisdg
    Mar 28 at 12:23




















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0
















The method that returns both directories and files is Directory.EnumerateFileSystemEntries






share|improve this answer



























  • 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 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






  • 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















0
















The method that returns both directories and files is Directory.EnumerateFileSystemEntries






share|improve this answer



























  • 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 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






  • 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













0














0










0









The method that returns both directories and files is Directory.EnumerateFileSystemEntries






share|improve this answer















The method that returns both directories and files is Directory.EnumerateFileSystemEntries







share|improve this answer














share|improve this answer



share|improve this answer








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 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






  • 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











  • 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











  • @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













0
















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/






share|improve this answer

























  • This is too complicated when you have a simpler handy solution. Check the duplicate question here.

    – aloisdg
    Mar 28 at 12:23
















0
















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/






share|improve this answer

























  • This is too complicated when you have a simpler handy solution. Check the duplicate question here.

    – aloisdg
    Mar 28 at 12:23














0














0










0









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/






share|improve this answer













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/







share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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




Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해