473,889 Members | 1,455 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?

May 2 '06 #1
5 98702
9,065 Recognized Expert Moderator Expert

fiFileInfo.Move To( Path.ChangeExte nsion(fiFileInf o.FullName + fiFileInfo.Exte nsion, ".enc") )
May 2 '06 #2
2 New Member
cheers, and im sorry, i should have known that..
May 3 '06 #3
3 New Member
It is better to use method
Path.ChangeExte nsion(string path, string extension);
Jan 29 '07 #4
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.         }
  18.         private int File_Delete(string Filepath)
  19.         {
  20.             FileInfo fi = new FileInfo(Filepath);
  22.             if (fi.Exists)
  23.             {
  24.                 fi.Delete();
  25.             }
  26.             return 1;
  27.         }
  29.         private int File_rename(string FilepathOld, string FilepathNew)
  30.         {
  31.             FileInfo fi = new FileInfo(FilepathOld);
  33.             if (fi.Exists)
  34.             {
  35.                 fi.MoveTo(FilepathNew);
  37.             }
  38.             return 1;
  39.         }
  41.         private void button1_Click(object sender, EventArgs e)
  43.         {
  45.             FileInfo fi = new FileInfo("C:\\dateiname.txt");
  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
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

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 )
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 user. In my code, I set a constant as follows: private const string tempMdb = @"C:\temp.mdb";
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,
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 ..
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
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 javascript to rename the file being downloaded? Thanks very much!
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))
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..
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 to the folder /upload.
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 appreciated as122223333443.txt = the new generated name is updated to this file that way the next...
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.