Solved

.Net Delete file in directory spaces in path

Posted on 2016-09-16
4
30 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 62

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

25 Experts available now in Live!

Get 1:1 Help Now