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
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ali G
NA
51
38.5k
Renaming As YYYY.MM.DD.001.JPG and Moving to YYYY.MM.DD
Oct 1 2013 10:12 AM
I asked similar before but still I don't have a usable answer. My codes read JPG file's date taken data and rename the files like YYYY.MM.DD.001.JPG . But every date must have its own sequence numbers.
And I need to move every file to a directory which has same name with the filename's date part (YYYY.MM.DD).
WOULD YOU CORRECT THESE CODES:
==============================
========
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;
using System.Drawing.Imaging;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
string pathname;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = folderBrowserDialog1.ShowDialo
g();
pathname = @folderBrowserDialog1.Selected
Path;
int JPGcount = Directory.GetFiles(@pathname, "*.JPG", SearchOption.AllDirectories).L
ength;
}
private void button2_Click(object sender, EventArgs e)
{
FileInfo[] files = new DirectoryInfo(pathname).GetFil
es("*.JPG");
for (int i = 0; i < files.Length; i++)
{
string DateAndTimePictureTaken = string.Empty;
Image image = new Bitmap(@files[i].FullName);
PropertyItem[] propItems = image.PropertyItems;
foreach (PropertyItem propItem in propItems)
{
if (propItem.Id == 0x0132)
{
DateAndTimePictureTaken = (new System.Text.ASCIIEncoding()).G
etString(propItem.Value);
image.Dispose();
string Year = DateAndTimePictureTaken.Substr
ing(0, 4);
string Month = DateAndTimePictureTaken.Substr
ing(5, 2);
string Day = DateAndTimePictureTaken.Substr
ing(8, 2);
string PhotoNumber = (i + 1).ToString().PadLeft(3, '0');
string newFile = String.Format("{0}.{1}.{2}.{3}
.{4}", Year, Month, Day, PhotoNumber, "JPG"); // PhotoNumber MUST START FOR EVERY DATE.
string fullNewPath = files[i].DirectoryName;
string newFileWithPath = Path.Combine(fullNewPath, newFile);
File.Move(files[i].FullName, newFileWithPath); //NEEDED TO MOVE TO A FOLDER NAMED YYYY.MM.DD
break;
}
}
}
}
}
}
==============================
========
Reply
Answers (
3
)
Call by Reference And Call by value
VB .Net Application