using namespace std;
ofstream myfile;
//myfile.open ("Z:\\ABC.TXT"); // fails Z: is a network drive
//myfile.open("C:\\Temp\\ABC.TXT"); // OK
//myfile.open("Z:\\NETWORK\\02-010E.CHS"); // fails Z:\Network is a network folder
if (myfile.is_open())
cout << "file is open" << endl;
else
cout << "file fails to open" << endl;
myfile.close();
Question: It seems that ofstream.open
doesn't support to open a file on a network drive.
Is there a simply way to solve this issue?
Open File Explorer from the taskbar or the Start menu, or press the Windows logo key + E. Select This PC from the left pane. Then, on the Computer tab, select Map network drive. In the Drive list, select a drive letter.
View Open Files on a Shared Network Folder on Windows Server Open the Computer Management console on your file server (or connect to the server remotely from the management console running on your computer) and go to System Tools -> Shared Folders -> Open files.
The easiest way to find a list of network shared folders is to use File Explorer (Windows 10) or Windows Explorer (Windows 8 and Windows 7). Open Windows File Explorer, go to the Folders pane, and select Network. Select the computer that has the shared folders you want to browse.
Try this:
using namespace std;
ofstream myfile;
myfile.open("\\\\servername\\filepath\\filename");
//^^should follow this format, servername is not Z drive name
if (myfile.is_open())
cout << "file is open" << endl;
else
cout << "file fails to open" << endl;
myfile.close();
I tried this to open a file on a shared server, it outputs
file is open
so it should work.
The Z
drive is actually not real physical drive, it is just a mapping to real physical drive on the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With