473,544 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

rename file in c#

2 New Member
i use:
fiFileInfo.Copy To(Path.ChangeE xtension(fiFile Info.FullName + fiFileInfo.Exte nsion, ".enc"), false);
to rename a file (eg: crap.ppt -> crap.ppt.enc).

if the file is really big (400mb), this take 6-7 minutes. is there a better way to rename files?

regards
meeeeeeeeeep
May 2 '06 #1
5 98685
Banfa
9,065 Recognized Expert Moderator Expert
try

fiFileInfo.Move To( Path.ChangeExte nsion(fiFileInf o.FullName + fiFileInfo.Exte nsion, ".enc") )
May 2 '06 #2
meeeeeeeeeep
2 New Member
cheers, and im sorry, i should have known that..
May 3 '06 #3
Mihania
3 New Member
It is better to use method
Path.ChangeExte nsion(string path, string extension);
Jan 29 '07 #4
jon79de
1 New Member
OK here the easist way with all descriptions:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.IO;
  9. namespace rhozetApplication3
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.  
  18.         private int File_Delete(string Filepath)
  19.         {
  20.             FileInfo fi = new FileInfo(Filepath);
  21.  
  22.             if (fi.Exists)
  23.             {
  24.                 fi.Delete();
  25.             }
  26.             return 1;
  27.         }
  28.  
  29.         private int File_rename(string FilepathOld, string FilepathNew)
  30.         {
  31.             FileInfo fi = new FileInfo(FilepathOld);
  32.  
  33.             if (fi.Exists)
  34.             {
  35.                 fi.MoveTo(FilepathNew);
  36.  
  37.             }
  38.             return 1;
  39.         }
  40.  
  41.         private void button1_Click(object sender, EventArgs e)
  42.  
  43.         {
  44.  
  45.             FileInfo fi = new FileInfo("C:\\dateiname.txt");
  46.  
  47.             if (fi.Exists)
  48.             {
  49.                 fi.MoveTo("C:\\dateiname.mpg");
  50.                 textBox1.Text = "           Succesfull!    ";
  51.             }
  52.             else
  53.             {
  54.                 textBox1.Text = "           Failed!    ";
  55.             }
  56.         }
  57.     }}
\\ a button and a text box is requiert to run it

have fun
Oct 16 '07 #5
tlhintoq
3,525 Recognized Expert Specialist
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Nov 6 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4891
by: andrewcw | last post by:
Is there a simpler way to rename a file other than copy the source file to the target file, then deleting the source file ? { i did not see any rename in the File class )
5
2737
by: jez123456 | last post by:
Hi, I’ve written a c# program to compact certain msaccess databases. The way this works is to compact say C:\test1.mdb to C:\temp.mdb, then delete C:\test1.mdb and rename C:\temp.mdb as C:\test1.mdb. My problem occurs if there is already a C:\temp.mdb file. I don’t want to just delete this, as it could have been created separately by a...
2
2946
by: Bruce Russell | last post by:
This may sound stupid but I can't rename the WebForm1.aspx in the solution explorer. The file is located in my local web server at C:\Inetpub\wwwroot\Lab3-VB-Starter\WebForm1.aspx Is there some configuration problem in my IIS setup? Thanks,
1
3009
by: John Howard | last post by:
I am attempting to rename a file in VB.net using the MSDN rename function example at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctrename.asp My code looks like this: Imports System.IO ..
3
11820
by: OdAwG | last post by:
Hello All, I would i check to see if a file exist and if it does exist, then rename the file with the date and time attached to the name: Example: If File.Exists("\\server\share\folder\myfile.txt") Then rename \\server\share\folder\myfile.txt \\server\share\folder\myfile_date_time.txt
1
4123
by: googlegroups | last post by:
I have a standard template file that is available for download (currently just an anchor tag). I would like to rename the file that is sent to the client (to include an ID used by the template) so if the user saves the file rather than opens it, it will have the necessary info to work properly when it is opened. Is there a means via...
0
1385
by: aris1234 | last post by:
how to rename file name in DB..??? this my code, but this code only save image to folder, can't rename file in DB : <?php //Сheck that we have a file $folder = "../property/$spid"; if(!file_exists($folder))
8
6874
by: jack | last post by:
Hi, I have more than 1000 photos in my system but with very untidy name. Im trying to create a program through which i can rename the file. I have seen the examples on net an forums, but the only solution seems to be with moving the file with different name. I don't want to move the file but just want to rename it..
4
5255
by: PHPstarter | last post by:
Hi guys. I'm having a problem with this case. I want a php script activated by a standard file submit to: 1) upload the file to ../../upload 2) copy the file to a directory further back, for example .././latest/../.. 3) rename the file, no matter what name it has - to play.html So far I got the upload working and the file is uploaded...
1
2344
by: fogsys | last post by:
ok here is what Im trying to create: simple code that renames the file to be downloaded each time someone downloads it. example: you download my file, it will be rename to smth different that way you cant access the file using that URL anymore here is the code: for some reasons the renaming part doesnt work. any input would be greatly...
0
7414
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7598
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. ...
1
5288
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...
0
4905
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...
0
3400
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...
0
3398
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1833
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
651
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...

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.