Search folder and get files [duplicate] - c#

This question already has answers here:
C# Searching for files and folders except in certain folders
(4 answers)
Closed 8 years ago.
I am having one folder containing all .jpg files. Now I am having some part of file name. I want all files whose name contains that part from that folder.
thank you in advance...

You can use DirectoryInfo.EnumerateFiles to do this. And just give it the search pattern.

Related

Path of a folder inside my project [duplicate]

This question already has answers here:
get path for my .exe [duplicate]
(4 answers)
Closed 5 years ago.
So I'm trying to find a way of accesing the path of the folder to copy files but I can't find a way to do it
string folderpath = "C:\Users\Marc Vila\Downloads\Version 3.5\WindowsForm1\WindowsForm1/Resources";
I don't want to do that because as soon as I move it it gives me an error, anyone knows a more efficient way to do it?
Thanks and regards
Note: I've tried System.IO but it gives me a lot of trouble
You need to get the assembly's path and then build a relative path on top of that.
Take the code from this answer and then use that to combine the paths:
var folderPath = Path.Combine(AssemblyDirectory, "Resources");

File.Move all files of type [duplicate]

This question already has answers here:
Visual C#: Move multiple files with the same extensions into another directory
(2 answers)
Closed 5 years ago.
The following code is working, but I need to amend it so it moves all .txt files instead of just the test.txt file.
File.Move(#"C:\Desktop\test\test.txt", #"C:\Desktop\test\old\test.txt");
How can I amend it to do this?
It's moving them from the test folder to the test\old subfolder
whith this you can get all files with path and after that with for you can copy all files to your path
string[] files = System.IO.Directory.GetFiles(path, "*.txt");

Opening A File With Code [duplicate]

This question already has answers here:
Open file with associated application
(3 answers)
Closed 5 years ago.
I have a string of the file path and I want to open the file. Not in the way that it shows bytes in the console for example, but to open the original file with the program that suits him.
For example if my path shows a .docs file I want it to be opened with Word.
Any suggestions?
System.Diagnostics.Process.Start("CMD.exe",filePath);

cut last slash and item for path in c# [duplicate]

This question already has answers here:
How do I find the parent directory of a path?
(4 answers)
Closed 6 years ago.
I would like to cut last slash and corresponding file or folder given path in string variable (called pathVar)
For example, if pathVar = "c:\temp\a\b\c"
I would like to assign to newPathVar = "c:\temp\a\b"
What is the easier and best way in c# to do that?
Thanks!
You can use Path.GetDirectoryName for that.

How do I get a list of files in c# from a directory path which contains wildcards? [duplicate]

This question already has answers here:
How to implement glob in C#
(4 answers)
Closed 6 years ago.
Given a path c:\someFolder\**\*.exe. How can I get a list of files using this directory path. I know that one could use Directory.GetFiles(directoryPath) but this only works when there are no wildcard characters in directoryPath.
See: How to implement glob in C#

Categories