Solved

.Net Delete file in directory spaces in path

Posted on 2016-09-16
4
27 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
Comment Utility
.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
Comment Utility
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
Comment Utility
Thanks
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now