Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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
 
Old August 11th, 2006, 02:00 PM
Authorized User
 
Join Date: Aug 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to shivanshub
Default 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.
 
Old August 14th, 2006, 02:27 AM
Registered User
 
Join Date: Mar 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vishald
Default

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
 
Old August 14th, 2006, 10:40 AM
Authorized User
 
Join Date: Aug 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to shivanshub
Default

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
 
Old August 14th, 2006, 02:15 PM
Authorized User
 
Join Date: Aug 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old August 14th, 2006, 02:29 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old August 14th, 2006, 05:12 PM
Authorized User
 
Join Date: Aug 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old August 15th, 2006, 02:41 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
 
Old August 15th, 2006, 12:37 PM
Authorized User
 
Join Date: Aug 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old August 15th, 2006, 01:35 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old August 15th, 2006, 02:58 PM
Authorized User
 
Join Date: Aug 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to shivanshub
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename web site, aspx, folder in VS 2005? cJeffreywang BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 July 9th, 2007 11:40 AM
How To rename and delete from file shivanshub .NET Framework 2.0 2 August 18th, 2006 11:53 AM
Rename File/Folder shivanshub General .NET 0 August 11th, 2006 01:57 PM
Rename file without time change surendran PHP How-To 1 July 26th, 2006 05:38 AM
How to create a folder in server and rename files pramos.21d ASP.NET 2.0 Basics 0 April 24th, 2006 05:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.