By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,925 Members | 732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,925 IT Pros & Developers. It's quick & easy.

rename file in c#

P: 2
i use:
fiFileInfo.CopyTo(Path.ChangeExtension(fiFileInfo. FullName + fiFileInfo.Extension, ".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

✓ answered by Banfa

try

fiFileInfo.MoveTo( Path.ChangeExtension(fiFileInfo.FullName + fiFileInfo.Extension, ".enc") )

Share this Question
Share on Google+
5 Replies


Banfa
Expert Mod 5K+
P: 8,916
try

fiFileInfo.MoveTo( Path.ChangeExtension(fiFileInfo.FullName + fiFileInfo.Extension, ".enc") )
May 2 '06 #2

P: 2
cheers, and im sorry, i should have known that..
May 3 '06 #3

P: 3
It is better to use method
Path.ChangeExtension(string path, string extension);
Jan 29 '07 #4

P: 1
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
Expert 2.5K+
P: 3,525
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

Post your reply

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