Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compiler Issues DOS Filename Lengths

Status
Not open for further replies.

Watts

Programmer
Jan 18, 2001
80
US
I have a program when run on a file, it generates another file which is basically the same with a few things added in.

The new file has an added '_' in front of the orignal filename. Example:

indexcfg.htm becomes _indexcfg.htm

As you've noticed some of my filenames are 8 characters in length and when a '_' is added, the filename becomes 9 characters in length and a '~' is then added because of MSDOS filenaming.

Is there a way to use the compiler to tell the application that is okay to save with windows filename lengths of more than 8 characters? There has to be a way since the previous version of this application (which I modified) worked nicely.
 
What does it have common with C++? John Fill
1c.bmp


ivfmd@mail.md
 
I am using the microsoft visual C++ 6.0 CL compiler to build the application. I am sure someone has written a simple program that parses an input file and creates an output file from the DOS prompt using C++? There are no windows involved, just a simple command prompt application with two inputs, the name of the input file and the name of the output file.

I want the program to be able to save using Windows filename lengths of more than 8 characters without saving them with the '~' character in the name.
 
If you make a console program do it:

#include<string>
#include<fstream>
#include<windows.h>
#include<iostream>
using namespace std;
int main(int _args,char** _cmdline)
{
string read_path;
if(_args>1)
{
read_path=_cmdline[1];
for(int i=2;i<_args;i++)
{
read_path+=&quot; &quot;;
read_path+=_cmdline;
}
cout<<read_path.begin()<<endl;
}
CreateDirectory((read_path+&quot;\\new&quot;).begin(),0);
ofstream((read_path+&quot;\\new\\file with spaces in a long name.txt&quot;).begin());
//creates a file in the subdirectory new of directory name from command line which can be with or without spaces.

More simple is to do it in WinAPI programs

#include<fstream>
using namespace std;
int WINAPI WinMain(HINSTANCE,HINSTANCE,int,LPSTR cmdline)
{
ofstream(cmdline);//creates a full anme file what is in
//cmdline
return 0;
}

This program doesn't have windows, but in command line you can run it well. John Fill
1c.bmp


ivfmd@mail.md
 
Here is the code I am using:

void main(int argc, char *argv[])
{
FILE *infile, *outfile;

infile = fopen(argv[1], &quot;rb&quot;);
if (infile == NULL) {
perror(argv[1]);
exit(-1);
}

outfile = fopen(argv[2], &quot;wb&quot;);
if (outfile == NULL) {
fclose(infile);
exit(-1);
}

if (check_realtime_data(infile))
fprintf(outfile, &quot;%s\r\n&quot;, REALTIME_DATA);
else
fprintf(outfile, &quot;%s\r\n&quot;, NO_REALTIME_DATA);

// write the C file
while (fgets(input_str, 256, infile) != NULL) {
fprintf(outfile, &quot;%s&quot;, input_str);
}

fclose(infile);
fclose(outfile);
}

If argv[2] happens to be greater than 8 characters, the file is created with a '~' in the name. This is not acceptable... I need to allow long filenames. Sorry for the confusion and thanks for the sample code, but I already have this going for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top