Search results for 'BlackJack'. 1 post(s) found.

  1. 2008/03/12 How to rename(change file name) in C# ? (1)
2008/03/12 10:32

How to rename(change file name) in C# ?


Simplest way to change file name in C# is using File.Move() function.

Here's the simple example change file name for Samsung Black Jack Phone. However it may work on another platform if it supports .NET compact framework.

In addition, File creation time can be obtained by FileInfo class. See the below example for addition example.

//
// Programmed 2008 by Kurapa Chunun Kang (kurapa@kurapa.com)
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; // added for FileInfo class

namespace fnc
{
    class Program
    {
       // developed for Samsung Black Jack Smart Phone
        static void KChangeFileNameForBlackJack(string strDir)
        {
            int iocnt = 100;
            DirectoryInfo dir = new DirectoryInfo( strDir);
            FileInfo[] bmpfiles = dir.GetFiles("PIC-*.jpg");
            Console.WriteLine("Total number of bmp files", bmpfiles.Length);
            foreach (FileInfo f in bmpfiles)
            {
                String fn = f.CreationTime.Year + "-"
                            + ((f.CreationTime.Month<10) ? "0":"") + f.CreationTime.Month + "-"
                            + ((f.CreationTime.Day < 10) ? "0" : "") + f.CreationTime.Day + "_"
                            + ((f.CreationTime.Hour < 10) ? "0" : "") + f.CreationTime.Hour
                            + ((f.CreationTime.Minute < 10) ? "0" : "") + f.CreationTime.Minute
                            + ((f.CreationTime.Second < 10) ? "0" : "") + f.CreationTime.Second
                            + (iocnt++)
                            + ".jpg";
                File.Move( strDir + "\\" + f.Name, strDir + "\\" + fn);
            }
        }

        static void Main(string[] args)
        {
            KChangeFileNameForBlackJack(@"\Storage Card\My Pictures");
        }
    }
}


Trackback 0 1

Trackback : Cannot send a trackbact to this post.