473,394 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

system(), renaming files and long filenames

I am trying to create a DOS utility that will extract data from a file and
use it to form a new filename for that same file. I can successfully open
the file, get the data I need and form the new name, but it truncates and
renames it in the 8.3 format. If the newly formed name is
"LongFilename.ext", the file gets renamed to "LONGFILE.EXT".

I'm currently using the following statements to rename the file:

sprintf( buf, "ren %s %s", old_name, new_name );
system( buf );

I even tried placing quotes around the new_name, but the system() function
reports an error message.

I'm working with old tools, so that might be part of the problem, but maybe
there is a simple solution to this. I would appreciate any help. Thanks.

I'm using Borland Turbo C++ 3.0 for DOS.

----------------------------------
Pegboy
Nov 13 '05 #1
6 5926
Pegboy <pe****@neb.rr.com> wrote:
I am trying to create a DOS utility that will extract data from a file and
use it to form a new filename for that same file. I can successfully open
the file, get the data I need and form the new name, but it truncates and
renames it in the 8.3 format. If the newly formed name is
"LongFilename.ext", the file gets renamed to "LONGFILE.EXT". I'm currently using the following statements to rename the file: sprintf( buf, "ren %s %s", old_name, new_name );
system( buf ); I even tried placing quotes around the new_name, but the system() function
reports an error message.
If this would work you would try to rename a (probably non-existent) file
named "old_name" to a file named "new_name".
I'm working with old tools, so that might be part of the problem, but maybe
there is a simple solution to this. I would appreciate any help. Thanks.


This isn't really a C question but is a problem with the operating system
you're using, so you better ask in a DOS related newsgroup like
comp.msdos.programmer.

To get this back on-topic, why don't you use system() when there's a
standard C function for the purpose, appropriately named rename()?
From K&R2:

int rename( const char *oldname, const char *newname )

rename changes the name of a file; it returns non-zero if the attempt fails.

Of course, it might fail if you try to rename a file to something that
your OS does not like...
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Je***********@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
Nov 13 '05 #2

"Pegboy" <pe****@neb.rr.com> wrote in message
news:lU******************@twister.rdc-kc.rr.com...
I am trying to create a DOS utility that will extract data from a file and
use it to form a new filename for that same file. I can successfully open
the file, get the data I need and form the new name, but it truncates and
renames it in the 8.3 format. If the newly formed name is
"LongFilename.ext", the file gets renamed to "LONGFILE.EXT".

I'm currently using the following statements to rename the file:

sprintf( buf, "ren %s %s", old_name, new_name );
system( buf );

I even tried placing quotes around the new_name, but the system() function
reports an error message.

I'm working with old tools, so that might be part of the problem, but maybe there is a simple solution to this. I would appreciate any help. Thanks.

I'm using Borland Turbo C++ 3.0 for DOS.


sprintf(buf, "ren \"%s\" \"%s\"", old_name, new_name);

Note that you can also use the standard library function
'rename()' to rename a file, without needing to call
'system()'.
-Mike
Nov 13 '05 #3
Thanks guys. I will check with with a DOS related group.

I am using rename()now and still limited to 8.3 but now can use lower-case
letters.

------------------------
Pegboy
"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:iL*****************@newsread1.news.pas.earthl ink.net...

"Pegboy" <pe****@neb.rr.com> wrote in message
news:lU******************@twister.rdc-kc.rr.com...
I am trying to create a DOS utility that will extract data from a file and use it to form a new filename for that same file. I can successfully open the file, get the data I need and form the new name, but it truncates and renames it in the 8.3 format. If the newly formed name is
"LongFilename.ext", the file gets renamed to "LONGFILE.EXT".

I'm currently using the following statements to rename the file:

sprintf( buf, "ren %s %s", old_name, new_name );
system( buf );

I even tried placing quotes around the new_name, but the system() function reports an error message.

I'm working with old tools, so that might be part of the problem, but

maybe
there is a simple solution to this. I would appreciate any help. Thanks.
I'm using Borland Turbo C++ 3.0 for DOS.


sprintf(buf, "ren \"%s\" \"%s\"", old_name, new_name);

Note that you can also use the standard library function
'rename()' to rename a file, without needing to call
'system()'.
-Mike

Nov 13 '05 #4
Pegboy wrote:

I am trying to create a DOS utility that will extract data from
a file and use it to form a new filename for that same file. I
can successfully open the file, get the data I need and form the
new name, but it truncates and renames it in the 8.3 format. If
the newly formed name is "LongFilename.ext", the file gets
renamed to "LONGFILE.EXT".


The Dos filesystem has no place for more than the 8.3 name. Later
versions added a set of separate calls for the so-called LFN
extensions, but nothing of the sort existed when TC 3 was
created. So simply stick within the rules.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 13 '05 #5

I don't know if it will help you, but Horst Schaeffer's very useful
batch-related program VARSET10 gives the ability to get either the
short or the long file name into an environment variable (among many
other abilities). Since this is such a tiny program obviously written
in assembler, I was curious a couple years ago as to how it
accomplished this task and fired up DEBUG to look at the code.

As I suspected, there is a DOS function call (7160h) to do this. So I
wrote a little assembler function for use with Turbo C that gives the
long file name corresponding to a short file name.

I'll e-mail you Schaeffer's program and my assembler code in case you
find them instructive.
Nov 14 '05 #6
On Sat, 8 Nov 2003 15:07:59 -0600, "Pegboy" <pe****@neb.rr.com> wrote:

Assuming that you are running under Windows or some version of DOS
that supports long file names in the first place....

If nothing else works, try having your C program write a little batch
file that does the renaming, and then calling that batch file with
system().

If you are looking at a whole series of files, you can even build the
batch file one line at a time and finally call system() just once to
rename all the files.
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
28
by: AK | last post by:
Hi, I recently read an advice here that one should try to use make and version control system even if you're the only one working on the program. Is that a good advice? How many of you do that? ...
5
by: Raj | last post by:
Hi all, Can anyone help me with a script which would delete files or move them to a different folder at some scheduled time..! Please.....!!! Thanks in advance...
1
by: Don Leverton | last post by:
Hi Folks, I have been given a CD with approx 130 .xls files (bean-counters!) that I would like to import and merge to ONE table (tblTradeshow). The XL files are *similarly*, but not...
5
by: IdeaMan | last post by:
Windows 2000 Access 97 I am working on an issue tracking DB, where I need to link (not attach due to size)screen prints of various system errors. I have created a public folder on a network...
5
by: Robizzle | last post by:
I'm trying to write a simple console app that will rename all the files in a directory according to any rules supplied by a user during runtime. For example rename all *.jpg to *.jpeg. My problem...
0
by: Johan Delimon | last post by:
Hello, Ever got this error? The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248...
1
by: GeoDW | last post by:
Hell All, I have looked around and not found the solution I am looking for within the old threads. Here is my problem: I have a directory full of .img and .rrd files that have long filenames...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.