473,395 Members | 1,763 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,395 software developers and data experts.

What is C# equivalent of VB.Net Rename function?

VB.Net Rename function allow a file to be renamed or moved. How can I do
something similar in C# given that the rename function is not available in
C#?
Nov 16 '05 #1
5 3929
System.IO.File.Move()
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/
"Ben Wan" <a@a.a> wrote in message news:40********@news.iprimus.com.au...
VB.Net Rename function allow a file to be renamed or moved. How can I do
something similar in C# given that the rename function is not available in
C#?

Nov 16 '05 #2
Actually, the Rename function is available if you're willing to use
the Microsoft.VisualBasic namespace, but assuming you're not the true
.NET approach is:

System.IO.FileInfo test = new System.IO.FileInfo(sFileName);
//rename:
test.Name = sNewName;
//move:
test.MoveTo(sDestinationFileName);

Nov 16 '05 #3
I assume using Microsoft.VisualBasic namespace makes VB functions available
in C#. How is that done?
"Doknjas" <do*****@telus-dot-net.no-spam.invalid> wrote in message
news:40**********@127.0.0.1...
Actually, the Rename function is available if you're willing to use
the Microsoft.VisualBasic namespace, but assuming you're not the true
NET approach is:

System.IO.FileInfo test = new System.IO.FileInfo(sFileName);
//rename:
test.Name = sNewName;
//move:
test.MoveTo(sDestinationFileName);

Nov 16 '05 #4
Ben Wan <a@a.a> wrote:
I assume using Microsoft.VisualBasic namespace makes VB functions available
in C#. How is that done?


There's an assembly which basically mimics a lot of the VB
functionality. I would recommend against using it without making sure
that a "normal" .NET way of doing what you want isn't available first
though. People reading your C# code shouldn't have to be familiar with
VB, and they're much more likely to know about File.Move than the VB
Rename function.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Just use it like any other namespace in .NET -
"Microsoft.VisualBasic.Strings". But I agree with Jon Skeet - the
.net version is so simple that there's no reason to use the older VB
method.

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jerry Orr | last post by:
I'm writing a simple JNI C++ function on a z/OS 1.4 system. I am attempting to rename a dataset; however, when I use the rename() function, I get a return code of -1. All of the return codes listed...
3
by: Ben Wan | last post by:
VB.Net Rename function allow a file to be renamed or moved. How can I do something similar in C# given that the rename function is not available in C#?
1
by: Jay at SCA | last post by:
I've been having the following issue with a windows service I've created in vb.net (.net fw 1.1): Basically, my service monitors a folder for the creation of any new files of a particular type...
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...
5
by: Rothariger | last post by:
Hello.... i want to know if its posible to rename multiple files like windows does.. example: file zzzzzzz.doc file asdasd.doc file esfsefse.doc
3
by: Yannick Benoit | last post by:
Hi guys. I have like hundreds of pictures in a folder and then I use this function to rename them all to a following number. but very often I noticed that some pictures get lost and I dont know...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
6
by: shuaishuaiyes | last post by:
Hello everyone... I'm a Chinese student and my English is very poor...So excuse me if I make grammar mistake. I want to ask some questions about "rename". I'm a beginner, so my C ..... :) I...
3
by: gsoguerrilla | last post by:
Hi, I have limited knowledge in php and I am having trouble with uploading an image to a remote directory and resizing it if it's larger and renaming it to a unique id, while at the same time I...
1
by: Alien | last post by:
Hi, I am new to PHP and trying to move a zip file from one directory to another. I researched on the web on this and all fingers pointed to this rename() function. I tried writing a PHP script...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...

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.