?
Solved

.Net Delete file in directory spaces in path

Posted on 2016-09-16
4
Medium Priority
?
50 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
p_davis earned 2000 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 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