473,739 Members | 6,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.e xt", the file gets renamed to "LONGFILE.E XT".

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 5940
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.e xt", the file gets renamed to "LONGFILE.E XT". 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.prog rammer.

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***********@p hysik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oe rring
Nov 13 '05 #2

"Pegboy" <pe****@neb.rr. com> wrote in message
news:lU******** **********@twis ter.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.e xt", the file gets renamed to "LONGFILE.E XT".

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******@mkwah ler.net> wrote in message
news:iL******** *********@newsr ead1.news.pas.e arthlink.net...

"Pegboy" <pe****@neb.rr. com> wrote in message
news:lU******** **********@twis ter.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.e xt", the file gets renamed to "LONGFILE.E XT".

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.e xt", the file gets
renamed to "LONGFILE.E XT".


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********@yah oo.com) (cb********@wor ldnet.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
4964
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 webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
28
2829
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? Thanks, -AK
5
13275
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
3441
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 identically structured, and the first row does NOT contain field names. Some (actually most) of the column names *are* the same in all of the spreadsheets.
5
3228
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 drive to store these images, under the assumption that no one will originally save them to that location. To resolve this, I need to copy the file to this location without possibility of user error in selecting the correct folder (the DB is to be...
5
6466
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 is getting a list of all the files that are in the current directory. The only way I could figure out how to do it is to loop through all the possible file names and checking if each one exists, if it does then i'd push it's name into a queue...
0
495
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 characters. Since the .NET Framework does not support long filenames :-( I had to write a library that calls the WIN32 API and wraps those functions like System.IO.
1
7217
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 that need to be trimmed down because the program I am using to open these files lists them not only by the name, but by how many characters are in the name. Here is an example of a filename and how I want it to look afterward: ...
21
34429
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 obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
0
8792
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.