Jump to content

file rename

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
10 replies to this topic

#1
chetan21

chetan21

    Newbie

  • Members
  • PipPip
  • 14 posts
hi all
i need help to rename file using C with more than 8 character.
why rename function cannot take more than 8 charcter,is it because
DOS is not able to do the same.
am i correct?

Edited by chetan21, 25 May 2009 - 05:29 PM.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It depends on what your operating system is.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
Well, chetan mentioned DOS, so I'm assuming it's Windows. I didn't see a restriction like you mentioned in the documentation for it here. Where did you get this information?

#4
chetan21

chetan21

    Newbie

  • Members
  • PipPip
  • 14 posts
hi dargueta,
I am using windows XP(32 bit) os.
my problem is when i send path of filename with more than 8 characters like c:/chetan/1234567890.txt to rename function in c,then it rename file with 1st 8 character ie 12345678.txt
Requirement is at least 15 character.
same problem exist when we create folder

#5
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
Bizarre...Does this have to be cross-platform or is it okay to use Windows-native functions that won't work elsewhere?

#include <windows.h>

MoveFile(src,dest);



#6
hehewaffles

hehewaffles

    Newbie

  • Members
  • Pip
  • 9 posts
Or you could do it the cheap way, and read in the entire file from the old path, and output it to the new path. :)

#include <iostream>
#include <fstream>
using namespace std;


ifstream ifsOldFile( szOldPath );
ofstream ofsNewFile( szNewPath );
char cBuf[ 1024 ];
do {
    ifsOldFile.read( cBuf, 1024 );
    ofsNewFile.write( cBuf, 1024 );
} while( !ifsOldFile.eof( ) );
ifsOldFile.close( );
ofsOldFile.close( );

//do something to delete the file at szOldPath


#7
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
I really don't recommend that. That's definitely not how any operating system I know of renames or moves files.

#8
chetan21

chetan21

    Newbie

  • Members
  • PipPip
  • 14 posts
Thanks for your reply guys.
But same problem exists using iostream,fstream.
I don't have windows.h file, trying to get new compiler.

STILL NEED YOUR HELP

#9
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
Are you doing this from a C program, or a straight binary (i.e. COM-style, not to be confused with COM components) and just linking to C libraries?

#10
chetan21

chetan21

    Newbie

  • Members
  • PipPip
  • 14 posts
I am using old terbo C++,it does not have windows.h heder file.
As I could not find it anyhwhere,now trying to get new version of terbo c++.
what I don't understand why there is 8 character limit and what parametre is deciding this?

#11
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
Well there's your problem. Your compiler is so old the implementation is still 8.3 dependent. I'd suggest you download a free compiler if money's an issue; there's plenty of good ones out there. Microsoft provides Visual Studio Express for free. It's great for students and some commercial apps, but it does have its weird "features" as Microsoft likes to call them.

Visual Studio Express 2008

Alternatively you could download the GCC compiler, which is also great.