Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 11th, 2006, 02:00 PM
Authorized User
 
Join Date: Aug 2006
Location: Chandigarh, Chandigarh, India.
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.
Reply With Quote
  #2 (permalink)  
Old August 14th, 2006, 02:27 AM
Registered User
 
Join Date: Mar 2006
Location: Navi Mumbai, Maharastra, India.
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
Reply With Quote
  #3 (permalink)  
Old August 14th, 2006, 10:40 AM
Authorized User
 
Join Date: Aug 2006
Location: Chandigarh, Chandigarh, India.
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
Reply With Quote
  #4 (permalink)  
Old August 14th, 2006, 02:15 PM
Authorized User
 
Join Date: Aug 2006
Location: , , Netherlands.
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
Reply With Quote
  #5 (permalink)  
Old August 14th, 2006, 02:29 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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.
Reply With Quote
  #6 (permalink)  
Old August 14th, 2006, 05:12 PM
Authorized User
 
Join Date: Aug 2006
Location: , , Netherlands.
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
Reply With Quote
  #7 (permalink)  
Old August 15th, 2006, 02:41 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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
Reply With Quote
  #8 (permalink)  
Old August 15th, 2006, 12:37 PM
Authorized User
 
Join Date: Aug 2006
Location: , , Netherlands.
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
Reply With Quote
  #9 (permalink)  
Old August 15th, 2006, 01:35 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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.
Reply With Quote
  #10 (permalink)  
Old August 15th, 2006, 02:58 PM
Authorized User
 
Join Date: Aug 2006
Location: Chandigarh, Chandigarh, India.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:07 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.