 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 11th, 2006, 02:00 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Rename File/Folder
Hi pls help me. I want to rename folder/file in framework 1.1 but with out making any copy or temp file of original.
And other prob is I need to delete data from file and after that resize my file but with out making any copy (temp) of original file. Or by just using small size temp file but not to copy whole file.
Pls help by either by logical idea or by any built in class.
Thanking u.
__________________
I am not like every body else.
|
|

August 14th, 2006, 02:27 AM
|
|
Registered User
|
|
Join Date: Mar 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi
To rename a file you have no option then to copy the file and then delete the original file.You dont have a rename file command in .net1.1 or .net 2.0.
Regatds,
Vishal
VISHAL DUBE
|
|

August 14th, 2006, 10:40 AM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
sir, but there must me any logic or any other option to rename file.
pls try and i m trying too , if i will get the ans i will tell u if u will then pls tell me.
thanks 4 reply.
B.Tech(Computer Science) final year from Chandigarh,INDIA
|
|

August 14th, 2006, 02:15 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The way I rename files is by executing batch files. I do this only if the files are big else i will use the rename which create a copy first. Maybe renaming files with a batch file works for you.
Regards,
.NETmateur
Electrical Engineer
|
|

August 14th, 2006, 02:29 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
quote:You dont have a rename file command in .net1.1 or .net 2.0.
|
Really?? What about the File.Move method??
System.IO.File.Move(oldFileName, newFileName);
This moves a file to another location. If the folder is the same, but the file name is different, you've effectively renamed the file, no?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

August 14th, 2006, 05:12 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
Sure. Using "System.IO.File.Move(oldFileName, newFileName)" will rename the file effectively. I thought that if the destination file has the same name that it will be removed by this command which the DOS command "move" will do. It is a bit confusing but after trying the "System.IO.File.Move(oldFileName, newFileName)" method I see that it does not remove the destination file.
Regards,
.NETmateur
Electrical Engineer
|
|

August 15th, 2006, 02:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It doesn't? In what kind of application are you using this? How does your code look like? I can successfully switch file names with the following code:
Code:
if (System.IO.File.Exists(@"C:\Piet.txt"))
{
System.IO.File.Move(@"C:\Piet.txt", @"C:\Joop.txt");
}
else
{
System.IO.File.Move(@"C:\Joop.txt", @"C:\Piet.txt");
}
Also, when I change c:\ in d:\ the file is moved to another disk...
Imar
|
|

August 15th, 2006, 12:37 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar,
What I mean is as follows:
Lets say you have two files in the same directory "fileA.txt", "fileB.txt". I thought that if you use the method System.IO.File.Move(@"fileA.txt", @"fileB.txt") that it will replace "fileB.txt" with "fileA.txt". Now with the external DOS command MOVE in mind it is a bit confusing because the DOS MOVE command will replace the file.
Regards,
.NETmateur
Electrical Engineer
|
|

August 15th, 2006, 01:35 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I see.
Move in .NET throws an IOException when the destination file already exists.
You'll need to check for its existence and move it manually instead. A simple wrapper method could do that for you, so you can still use the familiar Move method syntax...
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

August 15th, 2006, 02:58 PM
|
|
Authorized User
|
|
Join Date: Aug 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks to all of u. now i know about rename. now pls tell me something about my 2nd prob.
waiting 4 solution.
B.Tech(Computer Science) final year from Chandigarh,INDIA
|
|
 |