Announcement

Collapse
No announcement yet.

I need to connect to a file on a shared drive but UNC path is not supported?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • I need to connect to a file on a shared drive but UNC path is not supported?

    Hey,

    I am making a chat room in C++ using the visual studio compiler, the chat room uses file streaming as the middle man with the information going into and being read from a .txt in a shared network folder and the program is in the DOS window, this may seem off topic talking about C++ and not batch scripting but I am able to use batch files along with my C++ main program to carry out certain tasks such as manage the files which I am leaving up to the C++ as of now which could be part of the problem.

    The problem that I am having is that I type the path for the shared folder but in run time the program complains that UNC paths are not supported and that it is defaulting to the default windows path which is obviously not what I want. On my user account it works fine because as far as my user is concerned the path for the shared publish folder begins with a drive letter because the shared folder that everything is happening is a part of my user, the problem occurs when I run it from another user because the path then becomes a \\ double backslash which relates to UNC. The only thing I have managed to find out is that I need to assign a drive letter to this path but im not 100% sure how to.

    Here is an example of what the path is write like now:

    \\xxxxx.local\users\xxxxxxxx\G\TR\xxxxxxxx\Publish \chat\Chat_Room.txt


    Any help will be much appreciated I have already tried other forums, if you need any more information just let me know.

    Thank you.

  • #2
    Re: I need to connect to a file on a shared drive but UNC path is not supported?

    Are you using managed C++ (ugh) or pure C++?

    Using UNC paths shouldn't be a problem. Can you provide as short extract as possible for the app that reproduces the problem?

    -vP

    Comment


    • #3
      Re: I need to connect to a file on a shared drive but UNC path is not supported?

      the program complains that UNC paths are not supported and that it is defaulting to the default windows path
      It is a default warning about the working directory cannot be set to a network path. That is a fact.
      I.e. when the batch is in that folder it is a standard message shown every time you start the batch.

      You can ignore the warning, but make sure to use absolute paths for every folder and file the program is calling.
      Or else,, you could map the drive on the fly:
      In the batch you can use pushD and popD (see sample below) for this.
      In other languages determine the first available drive letter and map the drive unpersistently, set the working directory, and when its done change the working directory an unmap the drive.

      Batch sample
      Code:
      @echo off & cls
      
      pushD "\\xxxxx.local\users\xxxxxxxx\G\TR\xxxxxxxx\Publish" ||(goto:endD when FAILED)
      
      CD /d "chat"
      
      echo %CD%
      
      popD
      :endD
      
      echo %CD%
      
      pause
      Last edited by Rems; 18th February 2011, 11:06.

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: I need to connect to a file on a shared drive but UNC path is not supported?

        Thank you for the script its just what I'm looking for, I am going to do some research on how to map a drive letter in C++ and if I have no luck I'll link batch files to my program and do it that way, I'm pretty sure I'm using pure C++ in visual studio 2008, here is some code that vonPryz requested.

        Code:
        	cout << "~~You are entering Chat_Room_1~~" << endl;
        	cout << "Please note that your name will be used as your chat ID in the chat form" << endl << endl; 
        	cout << "Please enter your name: ";
        	getline(cin, name);   
        
        	file.open("\\xxxxxxx.local\users\xxxxxx\G\TR\xxxxxx\Publish\chat\Chat_Room.txt", ios::out | ios::app);  
        	if (file.is_open())  // check if file is open
        	{
        	file << "System: ";
        	file << name;
        	file << " has entered the chat room" << endl;
        	file.close();
        	}
        		else
        		{
        			cout << "Cannot connect to Chat_Room_01" << endl;
        			system("pause");
        			exit(1); // close program 
        		}
        Thanks guys really appreciate all of your help.

        Comment

        Working...
        X