GIDForums

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 28-Sep-2006, 10:04
jac jac is offline
New Member
 
Join Date: Sep 2006
Posts: 24
jac is an unknown quantity at this point
Smile

Pathway for My Documents is...


Hi! I'm new to Visual C++ and I have a question to ask. I have created a program and I want it copies an existing file on CD to My Documents file when the program's running, just something like installation. I got a code but it's a sample as shown at below. I want to ask what is the pathway for My Documents file. The pathway given in the code below is "c:\\temp\\MyTest.txttemp" where data is copied to. In the pathway of My Documets file, got username and I donn't know what username is used by the user and how can I complete the pathway?

CPP / C++ / C Code:
using namespace System;
using namespace System::IO;

int main()
{
   String^ path = "c:\\temp\\MyTest.txt";
   String^ path2 = "c:\\temp\\MyTest.txttemp";
   FileInfo^ fi1 = gcnew FileInfo( path );
   FileInfo^ fi2 = gcnew FileInfo( path2 );
   try
   {
      // Create the file and clean up handles.
      FileStream^ fs = fi1->Create();
      if ( fs )
         delete (IDisposable^)fs;
      
      //Ensure that the target does not exist.
      fi2->Delete();
      
      //Copy the file.
      fi1->CopyTo( path2 );
      Console::WriteLine( "{0} was copied to {1}.", path, path2 );
      
      //Try to copy it again, which should succeed.
      fi1->CopyTo( path2, true );
      Console::WriteLine( "The second Copy operation succeeded, which is expected." );
   }
   catch ( Exception^ ) 
   {
      Console::WriteLine( "Double copying was not allowed, which is not expected." );
   }
}
Last edited by admin : 28-Sep-2006 at 10:44. Reason: Please insert your C code between [cpp] & [/cpp] tags
  #2  
Old 28-Sep-2006, 10:23
Alloishus Alloishus is offline
New Member
 
Join Date: Sep 2006
Posts: 15
Alloishus is on a distinguished road

Re: Pathway for My Documents is...


Windows has environment variables used for scripting. That might be the key here, although I have not tried it. The %USERPROFILE% environment variable resolves to C:\Documents and Settings\{username}\ on a WindowsXP machine.

You can do a search for Windows Environment variables and get a list of all of them. I think the key would be to use those like so:

String^ path2 = "%USERPROFILE%\My Documents\MyTest.txttemp";

You might have to play with that to get it to compile right. I am not sure though.
  #3  
Old 29-Sep-2006, 04:27
jac jac is offline
New Member
 
Join Date: Sep 2006
Posts: 24
jac is an unknown quantity at this point

Re: Pathway for My Documents is...


Thanks for your reply, Alloishus.
 

Recent GIDBlogGoing to Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
All my important documents may be lost! mr5 Computer Software Forum - Windows 2 15-Sep-2005 03:12
Transferring Data between documents pixienick MS Visual C++ / MFC Forum 6 18-Aug-2005 05:34
Apache2 config issues monev Apache Web Server Forum 2 28-Jun-2004 06:19
Can't view pages from another machine on the Intranet aevans Apache Web Server Forum 9 14-May-2004 02:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:29.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.