By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

DeleteFile in Visual C++ (coming from VB)

P: 8
Using Visual C++ 2010 Express here under XP Pro SP3. I've been using VBA for Access for several years and have done a few apps for myself in Visual Basic. I've been trying to get a better handle on C++. While I've been through some tutorials in C++, I'm really trying to grasp how to use some of the .NET-specific items, including ones I've used in VB with little or no problem. So I have been trying to essentially re-write some small programs that I've done in VB into C++ as an exercise.

The MSDN article on the DeleteFile method has examples for VB, but not for any other language. (ms127977)

In VB, this is accomplished by using the

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
at the start of the program. So in my C++ program I have

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <string>
  3. using namespace System;
  4. using namespace System::IO;
  5. using namespace System::Collections;
  6.  
The key thing here being that System::IO, I'm thinking. The command I have in VB is:

Expand|Select|Wrap|Line Numbers
  1. Dim logfile2 As String
  2. logfile2 = "\\Sharename\\directory\\filename.ext"
  3. My.Computer.FileSystem.DeleteFile(logfile2)
So I tried:
Expand|Select|Wrap|Line Numbers
  1. String^ logfile2 = "\\\\Sharename\\directory\\filename.ext"
  2. My::Computer::FileSystem::DeleteFile(logfile2);
but that gives me "'My' : is not a class or namespace name." However, when I try it as...

Expand|Select|Wrap|Line Numbers
  1. DeleteFile(logfile2);
I get "'DeleteFile' : identifier not found." I think that would be expected, except that since I thought I was specifying the "using namespace System::IO;" I was telling where to look for that. I'm clearly missing some key parts of the namespace specification to refer to this feature of .NET in C++, and I'm wondering if I should use C++'s remove() here. Of course, my goal is to use the same .NET features I used in my VB application simply re-written for C++.

I don't necessarily want the code. I want to understand what key piece I'm missing in understanding here.
Oct 22 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.