Here is the code:
Code Snippet
- #light
- open System
- open System.IO
- let title : string = "My Movie Organizer"
- Console.WriteLine(title)
- Console.WriteLine("This Application will move all files in a folder to subfolders with the first letter as the folder name.")
- Console.WriteLine("Please enter the path of the folder you want to organize")
- let folderPath : string = Console.ReadLine()
- if folderPath <> String.Empty then
- let dirInfo : DirectoryInfo = new DirectoryInfo(folderPath)
- for x : FileInfo in dirInfo.GetFiles() do
- let firstLetter : char = x.Name.Chars 0
- let currentDirectory : DirectoryInfo = new DirectoryInfo(String.Format("{0}\\{1}\\", folderPath, firstLetter.ToString()))
- //If the current folder exists, move the file there else create the folder then move th file
- if currentDirectory.Exists then
- let xFilePath : string = currentDirectory.FullName
- x.MoveTo(xFilePath + x.Name)
- else
- currentDirectory.Create()
- let xFilePath : string = currentDirectory.FullName
- x.MoveTo(xFilePath + x.Name)
- //Write out the file name and path
- Console.WriteLine(String.Format("Moving File {0} to Folder {1} ", x.FullName, currentDirectory.FullName))
- else
- Console.WriteLine("Please specify a base path")
- //Wait for key press to end
- let endValue : string = Console.ReadLine()
This is a very simple app and by no means enterprise level with error checking ,etc. Just a basic app to move some files around in F#.
1 comment:
A dynamic language with access to the robust .NET library? Awesome!
Post a Comment