Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

long file names

raanazraanaz Posts: 8Member
Hi,

I am having a problem in opening/accessing a file which has a long name, more than 8 characters of length. How can i access a file:
1- with a long name
2- two files with same name(more than 8 characters) having the last charcter different. For example, originalfile1.txt is shown as origin~1.txt and originalfile2.txt is shown as origin~2.txt in dos. How can i read these two files in C++.

I'll be grateful if anyone can help

Thanks in advance!!

Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    [b][red]This message was edited by stober at 2006-7-13 3:55:1[/red][/b][hr]
    : Hi,
    :
    : I am having a problem in opening/accessing a file which has a long name, more than 8 characters of length. How can i access a file:
    : 1- with a long name
    : 2- two files with same name(more than 8 characters) having the last charcter different. For example, originalfile1.txt is shown as origin~1.txt and originalfile2.txt is shown as origin~2.txt in dos. How can i read these two files in C++.
    :
    : I'll be grateful if anyone can help
    :
    : Thanks in advance!!
    :


    What compiler are you using? If you are using 16-bit compiler such as Turbo C then you don't have much choice but to use the 8.3 filenames you posted.


  • raanazraanaz Posts: 8Member
    : [b][red]This message was edited by stober at 2006-7-13 3:55:1[/red][/b][hr]
    : : Hi,
    : :
    : : I am having a problem in opening/accessing a file which has a long name, more than 8 characters of length. How can i access a file:
    : : 1- with a long name
    : : 2- two files with same name(more than 8 characters) having the last charcter different. For example, originalfile1.txt is shown as origin~1.txt and originalfile2.txt is shown as origin~2.txt in dos. How can i read these two files in C++.
    : :
    : : I'll be grateful if anyone can help
    : :
    : : Thanks in advance!!
    : :
    :
    :
    : What compiler are you using? If you are using 16-bit compiler such as Turbo C then you don't have much choice but to use the 8.3 filenames you posted.
    :
    :
    :
    Thanks for the reply stober....
    It is an Win32 console application in VC++. Is there a solution for the problem?
    Thanks in advance
  • stoberstober Posts: 9,765Member ✭✭✭
    : It is an Win32 console application in VC++. Is there a solution for the problem?


    what version of that compiler? I know all VC++ 6.0 and newer compilers support long filenames. VC++ 1.52C is a 16-bit compiler and does not. It was the last 16-bit compiler Microsoft produced.
  • raanazraanaz Posts: 8Member
    : : It is an Win32 console application in VC++. Is there a solution for the problem?
    :
    :
    : what version of that compiler? I know all VC++ 6.0 and newer compilers support long filenames. VC++ 1.52C is a 16-bit compiler and does not. It was the last 16-bit compiler Microsoft produced.
    :

    Its VC++ 6.0. The file with a long name is not being read. Also the one with a space in the name.
  • tsagldtsagld Posts: 621Member
    : : : It is an Win32 console application in VC++. Is there a solution for the problem?
    : :
    : :
    : : what version of that compiler? I know all VC++ 6.0 and newer compilers support long filenames. VC++ 1.52C is a 16-bit compiler and does not. It was the last 16-bit compiler Microsoft produced.
    : :
    :
    : Its VC++ 6.0. The file with a long name is not being read. Also the one with a space in the name.
    :
    There shouldn't be any problem reading the file. Post the code, please.


    Greets,
    Eric Goldstein
    http://www.gvh-maatwerk.nl


  • raanazraanaz Posts: 8Member
    : : : : It is an Win32 console application in VC++. Is there a solution for the problem?
    : : :
    : : :
    : : : what version of that compiler? I know all VC++ 6.0 and newer compilers support long filenames. VC++ 1.52C is a 16-bit compiler and does not. It was the last 16-bit compiler Microsoft produced.
    : : :
    : :
    : : Its VC++ 6.0. The file with a long name is not being read. Also the one with a space in the name.
    : :
    : There shouldn't be any problem reading the file. Post the code, please.
    :
    :
    : Greets,
    : Eric Goldstein
    : http://www.gvh-maatwerk.nl
    :
    :
    :
    Here's the relevant code:

    ifstream ifile;

    setpath(argv[1]);//change the working dir

    if(get_cdr_structure(format,values))//read the file structure
    {
    printlabel();

    //open the cdr
    ifile.open(argv[2]);
    if (ifile)
    {
    //my code
    }

    }

    The code works well if argv[2] contains a short path and a short name
    Thanks in advance
  • tsagldtsagld Posts: 621Member
    : : : : : It is an Win32 console application in VC++. Is there a solution for the problem?
    : : : :
    : : : :
    : : : : what version of that compiler? I know all VC++ 6.0 and newer compilers support long filenames. VC++ 1.52C is a 16-bit compiler and does not. It was the last 16-bit compiler Microsoft produced.
    : : : :
    : : :
    : : : Its VC++ 6.0. The file with a long name is not being read. Also the one with a space in the name.
    : : :
    : : There shouldn't be any problem reading the file. Post the code, please.
    : :
    : :
    : : Greets,
    : : Eric Goldstein
    : : http://www.gvh-maatwerk.nl
    : :
    : :
    : :
    : Here's the relevant code:
    :
    : ifstream ifile;
    :
    : setpath(argv[1]);//change the working dir
    :
    : if(get_cdr_structure(format,values))//read the file structure
    : {
    : printlabel();
    :
    : //open the cdr
    : ifile.open(argv[2]);
    : if (ifile)
    : {
    : //my code
    : }
    :
    : }
    :
    : The code works well if argv[2] contains a short path and a short name
    : Thanks in advance

    Aha. Since the file is passed through an argument nd contains spaces, the runtime splits the filename in two or more arguments.
    You can verify that by inspecting argv[3]. You'll see that it contains the rest of the filename.
    Try passing the filename within double quotes.



    Greets,
    Eric Goldstein
    http://www.gvh-maatwerk.nl


  • stoberstober Posts: 9,765Member ✭✭✭
    : Aha. Since the file is passed through an argument nd contains spaces, the runtime splits the filename in two or more arguments.
    : You can verify that by inspecting argv[3]. You'll see that it contains the rest of the filename.
    : Try passing the filename within double quotes.
    :


    you can probably fix this problem by quoting the path on the command line
    [code]
    c:>myprogram.exe "an argument with spaces must be quoted here"
    [/code]
  • raanazraanaz Posts: 8Member
    : : Aha. Since the file is passed through an argument nd contains spaces, the runtime splits the filename in two or more arguments.
    : : You can verify that by inspecting argv[3]. You'll see that it contains the rest of the filename.
    : : Try passing the filename within double quotes.
    : :
    :
    :
    : you can probably fix this problem by quoting the path on the command line
    : [code]
    : c:>myprogram.exe "an argument with spaces must be quoted here"
    : [/code]
    :

    Thanks stober and tsagld, my problem is solved. I have added the following lines:

    strcpy(cdrpath,argv[2]);
    if(argc>3)
    for(int i=3;i<argc;i++)
    {
    strcat(cdrpath," ");
    strcat(cdrpath,argv[i]);
    }
    my code is working well with all sorts of filepaths and filenames.
    Thankyou!!!!!
  • tsagldtsagld Posts: 621Member
    [b][red]This message was edited by tsagld at 2006-7-24 23:37:41[/red][/b][hr]
    : : : Aha. Since the file is passed through an argument nd contains spaces, the runtime splits the filename in two or more arguments.
    : : : You can verify that by inspecting argv[3]. You'll see that it contains the rest of the filename.
    : : : Try passing the filename within double quotes.
    : : :
    : :
    : :
    : : you can probably fix this problem by quoting the path on the command line
    : : [code]
    : : c:>myprogram.exe "an argument with spaces must be quoted here"
    : : [/code]
    : :
    :
    : Thanks stober and tsagld, my problem is solved. I have added the following lines:
    [code]
    : strcpy(cdrpath,argv[2]);
    : if(argc>3) [red]this line is not really necessary[/red]
    : for(int i=3;i<argc;i++)
    : {
    : strcat(cdrpath," ");
    : strcat(cdrpath,argv[i]);
    : }
    [/code]
    : my code is working well with all sorts of filepaths and filenames.
    : Thankyou!!!!!

    [red]Realize that your code only works if the path is the last argument in the list. Besides that, you have to allocate space for cdrpath before you know how much space is needed. That's vulnerable to buffer overflows.
    As I stated before, it is better to pass the path between double quotes. Stober gave an example.
    [/red]

    Greets,
    Eric Goldstein
    http://www.gvh-maatwerk.nl




Sign In or Register to comment.