Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have property which holds filenameOnly without extension.
string fileNameOnly = "myFileName";
now I want to perform multiple checks on selected location for example c:\ for existed filename+fileextension (.jpg, .png, .gif, .bmp)
so, if c:\myFileName.jpg exist than assign that value to string filename="myFileName.jpg" variable.
what is the best and quickest way to do this?
Try something like this to get an array of files that fit your pattern:
string[] files = Directory.GetFiles(
DirectoryPath,
String.Format("{0}.*", fileNameOnly));
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hello I have multiple text files in one location and they have names as shown below:-
A_L_PRTD_021345.txt , A_L_PRTD_432124 and so on...
I want to append the contents into single file and want to rename the single file as L_PRTD_Currentdate>.txt
How is it possible?
Can you please show some code for it?
First read each file using File.ReadAllLines(fileName) ;
Then create a single file and append the contents of other files in it
string[] contents1 = File.ReadAllLines(fileName1) ;
string[] contents2 = File.ReadAllLines(fileName2) ;
File.Create(newFileNameHere) ;
File.WriteAllLines(newFileNameHere, contents1) ;
File.AppendAllLines(newFileNameHere, contents2) ;
and so on ...
Check the following documentation of the functions, if you need help:-
http://msdn.microsoft.com/en-us/library/92e05ft3(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/dd383691(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/s2tte0y1(v=vs.110).aspx
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a typed dataset with a column called price, which is of string datatype. And I'm showing this via ultrgrid/datagrid
How can I show the price in number format.
For example: price ==123456
in the grid it should be like 12,354,56
Try this
var a = price.ToString("##,###,##");
Reference
Custom Numeric Format Strings!
Look at some of the related links to the right of the screen. Some of them even ask the same question as you !
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm working on a program and to avoid complication I need to parse a given string variable to be a DirectoryInfo.
I was wondering if it were possible to parse a string to a DirectoryInfo.
If it is, how does one go about doing that?
Thanks
DirectoryInfo di = new DirectoryInfo(string);
MSDN, linked above, provides you the exceptions in case the string is invalid. Note: this is NOT if the directory exists. MSDN also makes note of this in the Remarks. You must then do:
if(di.Exists)
Well, it's not parsing, but the constructor for DirectoryInfo takes the path as a string:
DirectoryInfo di = new DirectoryInfo(#"c:\MyDir");
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following path...
'X:\Projects\4604-Renovation\Unity\4604_02\Assets\Models\FullBuilding\Materials\'
I want to split it at the directory 'Assets' and end up with...
'Assets\Models\FullBuilding\Materials\'
The directory 'Assets' will not always be in the same place in the path. How can I do this? Thanks.
Lets say your string is
string completePath = "X:\Projects\4604-Renovation\Unity\4604_02\Assets\Models\FullBuilding\Materials\";
string subPath = completePath.subString(completePath.IndexOf(#"Assets\"));
Please note that if your path contains multiple instances of Assests it will substring from first instance of Asset.
you can use path.IndexOf, you can use the str.SubString(str.IndexOf("\assetse")), you can do alot of things. playing with string is kinda fun...
most of the things you want to do with strings you can find on google anyway
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have created a WindowsApp.exe under Application\Setup folder. Now I want to create a Database under Application\Database folder from WindowsApp.exe
What should be the path given to the filename here?
try
Path.Combine(Environment.CurrentDirectory, "Database\\db1.mdb")
Edit
since you want the parent folder you can go up one folder by doing
Path.Combine(Environment.CurrentDirectory.Substring(Environment.CurrentDirectory.LastIndexOf("\\")), "Database\\db1.mdb")
Edit 2
if you want the Application folder even if its N times above the current folder then you can reach it by doing this
var index = Environment.CurrentDirectory.IndexOf(Environment.CurrentDirectory.IndexOf("ApplicationRootFolderName"),"\\")
var AppRootPath = Environment.CurrentDirectory.Substring(0,index);
Edit 3
As mentioned by Michael its better to get the parent folder using this way
Directory.GetParent(Environment.CurrentDirectory).FullName