473,387 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

rename file in c#

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") )

5 98679
Banfa
9,065 Expert Mod 8TB
try

fiFileInfo.MoveTo( Path.ChangeExtension(fiFileInfo.FullName + fiFileInfo.Extension, ".enc") )
May 2 '06 #2
cheers, and im sorry, i should have known that..
May 3 '06 #3
It is better to use method
Path.ChangeExtension(string path, string extension);
Jan 29 '07 #4
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 Expert 2GB
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
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
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...
2
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...
1
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...
3
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...
1
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...
0
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";...
8
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...
4
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.