How to get file list using system variable %LOCALAPPDATA%? [duplicate] - c#

This question already has answers here:
How do I get %LocalAppData% in c#?
(2 answers)
Closed 5 years ago.
I want to read the content of the folder located at %LOCALAPPDATA%. But it fails when I tried
Directory.GetDirectories("%LOCALAPPDATA%");
I get "The name 'Directory' does not exist in the current context"
Please help.

Environment.ExpandEnvironmentVariables

Related

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.

In File.Exists() how to know if the file is the reall file or a shortcut? [duplicate]

This question already has answers here:
Check if a file is real or a symbolic link
(9 answers)
How do i get the path name from a file shortcut ? Getting exception [duplicate]
(1 answer)
Closed 7 years ago.
I have a file in the folder like "c:\a\abc.mdb"
Sometimes someone could move it to somewhere else and leave a shortcut like "c:\a\abc.mdb.lnk".
In that case when I call IO.File.Exists(#"c:\a\abc.mdb") it still return true. In that case how can I verify if the real file exists, or whether the situation is:
abc.mdb exists only
abc.mdb.lnk exists only
or both of them exists?

Search folder and get files [duplicate]

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.

Get file modify date in C# [duplicate]

This question already has answers here:
Check last modified date of file in C#
(5 answers)
Closed 9 years ago.
How do I read the modify date of the file in C#?
I can read the creation date of the file by using the code below:
ModifyDate = File.GetCreationTime(FilePath)
File.GetLastWriteTime will do the job
I believe you're looking for GetLastWriteTime

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