TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Change Multiple File Extension using Windows Form
Piyush R.
Nov 12
2014
Code
2.2
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
//Please Fill free to ask query about this code,in case of error or have some changes to make will be accepted.
//Thank you for using this code.
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.IO;
//Use this Namespace.
namespace
ClientOM
{
public
partial
class
ExtnChanger : Form
{
public
ExtnChanger()
{
InitializeComponent();
}
private
void
btnclear_Click(
object
sender, EventArgs e)
{
txtpath.Text =
string
.Empty;
txtnewext.Text =
string
.Empty;
lblmsg.Text =
string
.Empty;
}
private
void
btnchngextn_Click(
object
sender, EventArgs e)
{
if
(txtpath.Text ==
string
.Empty || txtnewext.Text ==
""
)
{
lblmsg.Text =
string
.Empty;
MessageBox.Show(
"Directory Path/File Extension should not Empty."
,
"Info"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
try
{
string
dirpath = txtpath.Text.ToString();
string
[] filepath = Directory.GetFiles(dirpath);
foreach
(
string
myfile
in
filepath)
{
string
filename = Path.ChangeExtension(myfile, txtnewext.Text);
System.IO.File.Move(myfile, filename);
}
MessageBox.Show(
"File Extension has been changed successfully."
,
"Success"
, MessageBoxButtons.OK);
lblmsg.Text =
string
.Empty;
}
catch
(Exception ex)
{
MessageBox.Show(
"Invalid Directory/Filename!"
,
"Error"
, MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
}
}
// To Validate TextBox
private
void
txtpath_Leave(
object
sender, EventArgs e)
{
try
{
string
dirpath = txtpath.Text.ToString();
string
[] filepath = Directory.GetFiles(dirpath);
lblmsg.Text =
"Directory Contains '"
+ filepath.Length +
"' files inside."
;
}
catch
(Exception Ex)
{
lblmsg.Text =
"Invalid Directory/Filename!"
;
}
}
// To Validate Label
private
void
txtnewext_Leave(
object
sender, EventArgs e)
{
lblmsg.Text =
string
.Empty;
}
}
}
File Extension Change
Change Extension of multiple files