.Net Delete file in directory spaces in path

I have a process that deletes files in a directory that are older than three days old.

The path is acquired by reading the first line in a text file

That path can be anything from C:\temp to C:\Program FIles (386)

With that said...
Do I need to change this code to allow for spaces in the text file "directory" line?

DIm strPath as String  = File.ReadAllLines(Path.GetFullPath("directorypath.txt")).First()
Dim di As New System.IO.DirectoryInfo(strPath)
Who is Participating?
p_davisConnect With a Mentor Commented:
.NET should take care of interpreting the string in this case.
p_davisConnect With a Mentor Commented:
best to put it through a small test. make your own text file with file/folders that have spaces and breakpoint after the string assignment so you can look at the local value. that should answer your questions
lrbristerAuthor Commented:
Fernando SotoRetiredCommented:
That should work as long as the first line in the file is a valid directory path. So in your example you give this as a file path,

C:\Program FIles (386)
and it is not this which has an extra space in the name between s and (.
C:\Program FIles  (386)

Also I would use Trim function to remove any white spaces in front and end of the string.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.