Solved

.Net Delete file in directory spaces in path

Posted on 2016-09-16
4
34 Views
Last Modified: 2016-09-16
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)
0
Comment
Question by:lrbrister
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
p_davis earned 500 total points
ID: 41801478
.NET should take care of interpreting the string in this case.
0
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 500 total points
ID: 41801480
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
0
 

Author Closing Comment

by:lrbrister
ID: 41801481
Thanks
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41801487
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.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question