파일 이름 바꿔주는 프로그램

1초마다 지정된 파일을 감시해서, 파일이 존재하면 자동으로 다른 이름으로 바꿔준다.




Automover2.exe


‘Copyright: Keehwan Nam, 2012.

Public Class Form1

Private fn As String = “”

Private index As Integer = 0

Private begin As Integer = 0

Private istep As Integer = 1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

OpenFileDialog1.Multiselect = False

OpenFileDialog1.InitialDirectory = My.Application.Info.DirectoryPath

OpenFileDialog1.Title = “Set the file that you want to audit”

OpenFileDialog1.CheckFileExists = False

If OpenFileDialog1.ShowDialog <> System.Windows.Forms.DialogResult.Cancel Then

fn = OpenFileDialog1.FileName

Try

begin = CInt(TextBox1.Text)

Catch

MsgBox(“Please use integers only!”)

Exit Sub

End Try

Try

istep = CInt(TextBox2.Text)

Catch

MsgBox(“Please use integers only!”)

Exit Sub

End Try

Timer1.Enabled = True

End If

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Timer1.Enabled = False

If System.IO.File.Exists(fn) Then

Dim fns As String() = fn.Split(“.”)

Try


System.IO.File.Move(fn, System.IO.Path.GetDirectoryName(fn) & “\ThisFileMustNot.Exist”)



Do



Try



System.IO.File.Move(System.IO.Path.GetDirectoryName(fn) & “\ThisFileMustNot.Exist”, fn.Substring(0, fn.Length – fns(fns.Length – 1).Length – 1) & CStr(begin + (istep * index)) & “.” & fns(fns.Length – 1))

‘ 이 부분이 가장 신경쓴 부분이다. 자꾸 오류가 난대서…


Exit Do



Catch



End Try



index += 1



Loop



Catch


End Try

End If

Timer1.Enabled = True

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim tip As New ToolTip()

tip.AutoPopDelay = 5000

tip.InitialDelay = 1

tip.ReshowDelay = 1

tip.ShowAlways = True

tip.SetToolTip(Button1, “(c)Keehwan Nam,” & vbCr & “2012, APRI, GIST.”)

tip.SetToolTip(TextBox1, “Starting index”)

tip.SetToolTip(TextBox2, “Step”)

begin = CInt(TextBox1.Text)

istep = CInt(TextBox2.Text)

End Sub

End Class

실행에는 닷넷2.0이 필요하고 윈도우즈 전용이다. 바이러스가 의심가면 VB.net에서 위의 소스코드를 직접 빌드해도 된다. 디자인 소스는 생략.

뭐 이런걸 다 만드나 하겠지만, 누군가는 필요하고 누군가는 만들게 된다. 간단한 프로그램이라 그냥 민간에 공개한다. 코드를 읽어보면 알겠지만, 만들기가 매우 귀찮아 했다는 사실을 알 수 있다.

이 루틴을 잘 활용하면 실험실 자동화에 한걸음 다가갈 수 있을듯.

코멘트

“파일 이름 바꿔주는 프로그램”에 대한 2개 응답

  1. 
                  snowall
                  아바타

    이름붙이는건 제 마음입니다 ㅋㅋㅋ

    그리고 내부적으로 move함수를 사용하기 때문에 move도 맞아요

  2. 
                 goldenbug
                 아바타

    이름을 autorename이라고 해야 하지 않을까요? ^^

    대략 어떤 데 쓰려고 만드신 건지는 알겠습니다. ^^

댓글 남기기

이 사이트는 Akismet을 사용하여 스팸을 줄입니다. 댓글 데이터가 어떻게 처리되는지 알아보세요.