Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use this code to get all files name in a folder.
C#
rootFolder="D:\\rootFolder\\";
var videofilenames = Directory
                 .GetFiles(rootFolder, "*.*", SearchOption.AllDirectories)
                 .Select(s => Path.GetFileName(s))
                 .Where(s =>s.EndsWith(".mp4") || s.EndsWith(".mkv") || s.EndsWith(".wav") || s.EndsWith(".avi"));
            var videotop = videofilenames.Take(top);
            foreach (var myscore in videotop)
            {
                string videofilename = myscore.ToString();
             // and i store videofilename in an array
            }

now i need their path too.But I do not know how to change it to reach my aim.
thank you in advance.
Posted
Updated 20-Aug-14 21:20pm
v3
Comments
vangapally Naveen Kumar 21-Aug-14 2:00am    
please check what you are getting into 'videofilenames' .I Think you will get full file path into 'videofilenames'
4L4K1 21-Aug-14 2:32am    
string [] test=videofilenames.ToArray();
I checked it. it is just video file name without path
vangapally Naveen Kumar 21-Aug-14 2:42am    
see this link you may get some idea.
http://stackoverflow.com/questions/20375459/using-getfiles-but-splitting-the-results-to-show-full-path-and-just-the-filename

C#
DirectoryInfo dir=new DirectoryInfo(@"E:\Sidh\LabelHeight\LabelHeight\bin\Debug");
foreach (FileInfo file in dir.GetFiles("*.mkv"))
{
    MessageBox.Show(file.FullName);
}




try this
 
Share this answer
 
v2
C#
rootFolder="D:\\rootFolder\\";
static int top = 3810;

var videofilenames = Directory
.GetFiles(rootFolder, "*.*", SearchOption.AllDirectories)
.Where(s =>s.EndsWith(".mp4") || s.EndsWith(".mkv") || s.EndsWith(".wav") || s.EndsWith(".avi"));

            var videotop = videofilenames.Take(top);

            foreach (var myscore in videotop)
            {
                string Fullpath = myscore.ToString();
                string videofilepath = Path.GetDirectoryName(Fullpath) + "\\";
                string filename = Path.GetFileName(Fullpath);
                string fileformat = Path.GetExtension(filename);

            }


so now I have every thing :)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900