{"id":121,"date":"2008-05-06T15:10:57","date_gmt":"2008-05-06T20:10:57","guid":{"rendered":"http:\/\/mariusbancila.ro\/blog\/?p=121"},"modified":"2008-05-06T15:14:00","modified_gmt":"2008-05-06T20:14:00","slug":"applying-file-transformations-with-f","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/","title":{"rendered":"Applying File Transformations with F#"},"content":{"rendered":"<p>In this post I&#8217;ll show some F# constructs, all put together in a simple application that modifies file names that match a criteria. This would be an application that is started from a console with the following command line options:<\/p>\n<pre class=\"console\">\r\nfilesmod.exe -f &lt; folder &gt; [-r] -p &lt; pattern &gt; [-pre &lt; prefix &gt;] [-suf &lt; suffix &gt;]\r\n  -f &lt; folder>   specifies the folder where the files are located\r\n  -r            indicates that the specified folder should be parsed\r\n                recursively\r\n  -p &lt; pattern>  indicates a pattern used for filtering files\r\n  -pre &lt; prefix> indicats a prefix to the added to all files\r\n                that match the criteria\r\n  -suf &lt; suffix> indicats a suffix to the added to all files\r\n                that match the criteria\r\n<\/pre>\n<h3>Reading command line<\/h3>\n<p>The command line arguments can be retrieved using the Environment class from the .NET framework. This class has a static method called GetCommandLineArgs() that returns a list of the passed arguments.<br \/>\nWe can define a type that contains all the parsed arguments.<\/p>\n<pre class=\"prettyprint\">\r\ntype CommandOptions =\r\n    { mutable Folder : string;\r\n      mutable Recursive : bool;\r\n      mutable Pattern : string;\r\n      mutable Prefix : string;\r\n      mutable Suffix : string;}\r\n<\/pre>\n<p>This mutable record can be instantiated, and the value can be mutated while parsing the arguments. This is how you instantiate it:<\/p>\n<pre class=\"prettyprint\">\r\n   let cmdops =\r\n      { new CommandOptions\r\n        with Folder = String.Empty\r\n        and Recursive = false\r\n        and Pattern = String.Empty\r\n        and Prefix = String.Empty\r\n        and Suffix = String.Empty }\r\n<\/pre>\n<p>Parsing the command line arguments can be done with pattern matching. This is the equivalent of switches in C+\/C#\/Java, only more powerful.<br \/>\nBasically, I&#8217;m checking each argument, and if it&#8217;s a flag in the command line (-f, -r, -p, -pre, -sub) I take the next argument and put it in the appropriate property of the record.<\/p>\n<pre class=\"prettyprint\">\r\n   try\r\n      let args = Environment.GetCommandLineArgs()\r\n      for i = 0 to args.Length-1 do\r\n         match args.(i) with\r\n            | \"-f\" when i+1 &lt;= args.Length-1 -&gt; cmdops.Folder &lt;- args.(i+1)\r\n            | \"-r\" -&gt; cmdops.Recursive &lt;- true\r\n            | \"-p\" when i+1 &lt;= args.Length-1 -&gt; cmdops.Pattern &lt;- args.(i+1)\r\n            | \"-pre\" when i+1 &lt;= args.Length-1 -&gt; cmdops.Prefix &lt;- args.(i+1)\r\n            | \"-suf\" when i+1 &lt;= args.Length-1 -&gt; cmdops.Suffix &lt;- args.(i+1)\r\n            | _ -&gt; ()\r\n      done\r\n   with e -&gt; printfn \"%s\" e.Message\r\n<\/pre>\n<p>There are two things you could notice here. The first is the try &#8230; with block that makes sure any possible exception is caught.<br \/>\nThe second is the quarding the rules with the contidion that the current argument is not the last one in the list. (-f should be followed by a folder, -suf by a suffix, etc.)<br \/>\nYou can see what in the when statement:<\/p>\n<pre class=\"prettyprint\">\r\nwhen i+1 &lt;= args.Length-1\r\n<\/pre>\n<h3>Getting the files in a directory<\/h3>\n<p>We can get all files in a folder, using the following algorithm:<\/p>\n<ul>\n<li>get all the files in the current folder<\/li>\n<li>get all the sub-folders in the current folder and for each of them apply the algorithm again<\/li>\n<\/ul>\n<p>That is spelled &#8220;recursion&#8221;!. Our function should take several arguments: the path of a folder, a pattern for mathing filenames and a flag indicating whether sub-folders should be parsed or not.<\/p>\n<pre class=\"prettyprint\">\r\nlet rec allFiles dir pattern r =\r\n    seq\r\n        { for file in Directory.GetFiles(dir, pattern) do\r\n            yield file\r\n          if r then\r\n            for subdir in Directory.GetDirectories(dir) do\r\n                for file in allFiles subdir pattern r do\r\n                    yield file }\r\n<\/pre>\n<p>The above function is recursive and returns a sequence of file names. Sequences are lazy, which means that successive elements are computed and returned on demand, when they are needed.<br \/>\nThat is the opposite of a list or array, whose elements are created at once. The keyword &#8216;yield&#8217; here is used to return a new value as the sequence is iterated.<\/p>\n<h3>Processing the files<\/h3>\n<p>To process the files, we simply iterate over the sequence of files from the specified folder, match it against the provided parttern, and if there is a match, apply the prefix and\/or suffix transformation.<\/p>\n<pre class=\"prettyprint\">\r\n   for name in (allFiles cmdops.Folder \"*.*\" cmdops.Recursive) do\r\n      let file = new FileInfo(name)\r\n      if(Regex.IsMatch(file.Name, cmdops.Pattern, RegexOptions.Singleline)) then\r\n        let filename = file.Name.Substring(0, file.Name.LastIndexOf('.'))\r\n        let newname = file.Directory.FullName+\"\\\\\"+cmdops.Prefix+filename+cmdops.Suffix+file.Extension\r\n        System.IO.File.Move(file.FullName, newname)\r\n        printfn \"%s -&gt; %s\" file.FullName newname\r\n   done\r\n<\/pre>\n<p>Well, I have two cores on my machine, and since the Parallel FX framework is available, I like to use it. So here is the parallel version of that:<\/p>\n<pre class=\"prettyprint\">\r\n       try\r\n          Parallel.ForEach(allFiles cmdops.Folder \"*.*\" cmdops.Recursive, fun name -&gt;\r\n             let file = new FileInfo(name)\r\n             if(Regex.IsMatch(file.Name, cmdops.Pattern, RegexOptions.Singleline)) then\r\n                let filename = file.Name.Substring(0, file.Name.LastIndexOf('.'))\r\n                let newname = file.Directory.FullName+\"\\\\\"+cmdops.Prefix+filename+cmdops.Suffix+file.Extension\r\n                System.IO.File.Move(file.FullName, newname)\r\n                printfn \"%s -&gt; %s\" file.FullName newname)\r\n       with e -&gt; printfn \"%s\" e.InnerException.Message\r\n<\/pre>\n<p>The provided (via command line) pattern is a regular expression. Initially, the folder is checked for all files and then these files are matched against this regular expression.<\/p>\n<p>As I was saying in a previous post, if you use PFX, you have to add a reference to the System.threading.dll assembly, which requires a reference to the System.Core.dll assembly.<br \/>\nThat should be specified at the project&#8217;s propertyes.<\/p>\n<blockquote><p>\n-r C:\\WINDOWS\\assembly\\GAC_MSIL\\System.Core\\3.5.0.0__b77a5c561934e089\\System.Core.dll -r &#8220;C:\\Program Files\\Microsoft Parallel Extensions Dec07 CTP\\System.Threading.dll&#8221;\n<\/p><\/blockquote>\n<h3>Putting all together<\/h3>\n<p>All that put together looks like this:<\/p>\n<pre class=\"prettyprint\">\r\n#light\r\n\r\nopen System\r\nopen System.IO\r\nopen System.Text.RegularExpressions\r\n\r\nopen System.Threading\r\n\r\nlet rec allFiles dir pattern r =\r\n    seq\r\n        { for file in Directory.GetFiles(dir, pattern) do\r\n            yield file\r\n          if r then\r\n            for subdir in Directory.GetDirectories(dir) do\r\n                for file in allFiles subdir pattern r do\r\n                    yield file }\r\n\r\nlet showUsage() =\r\n    printfn \"filesmod.exe -f &lt; folder &gt; [-r] -p &lt; pattern &gt; [-pre &lt; prefix &gt;] [-suf &lt; suffix &gt;]\"\r\n    printfn \"  -f &lt; folder &gt;\\tspecifies the folder where the files are located\"\r\n    printfn \"  -r\\t\\tindicates that the specified folder should be parsed\\n\\t\\trecursively\"\r\n    printfn \"  -p &lt; pattern &gt;\\tindicates a pattern used for filtering files\"\r\n    printfn \"  -pre &lt; prefix &gt;\\tindicats a prefix to the added to all files\\n\\t\\tthat match the criteria\"\r\n    printfn \"  -suf &lt; suffix &gt;\\tindicats a suffix to the added to all files\\n\\t\\tthat match the criteria\"\r\n\r\ntype CommandOptions =\r\n    { mutable Folder : string;\r\n      mutable Recursive : bool;\r\n      mutable Pattern : string;\r\n      mutable Prefix : string;\r\n      mutable Suffix : string;}\r\n\r\nlet main()=\r\n   let cmdops =\r\n      { new CommandOptions\r\n        with Folder = String.Empty\r\n        and Recursive = false\r\n        and Pattern = String.Empty\r\n        and Prefix = String.Empty\r\n        and Suffix = String.Empty }\r\n     \r\n   try\r\n      let args = Environment.GetCommandLineArgs()\r\n      for i = 0 to args.Length-1 do\r\n         match args.(i) with\r\n            | \"-f\" when i+1 &lt;= args.Length-1 -&gt; cmdops.Folder &lt;- args.(i+1)\r\n            | \"-r\" -&gt; cmdops.Recursive <- true\r\n            | \"-p\" when i+1 &lt;= args.Length-1 -&gt; cmdops.Pattern &lt;- args.(i+1)\r\n            | \"-pre\" when i+1 &lt;= args.Length-1 -&gt; cmdops.Prefix &lt;- args.(i+1)\r\n            | \"-suf\" when i+1 &lt;= args.Length-1 -&gt; cmdops.Suffix &lt;- args.(i+1)\r\n            | _ -&gt; ()\r\n      done\r\n   with e -&gt; printfn \"%s\" e.Message\r\n\r\n   if ((String.IsNullOrEmpty(cmdops.Prefix) &#038;&#038; String.IsNullOrEmpty(cmdops.Suffix)) || \r\n        String.IsNullOrEmpty(cmdops.Pattern) || \r\n        String.IsNullOrEmpty(cmdops.Folder)) then\r\n        showUsage()\r\n   else\r\n       try\r\n          Parallel.ForEach(allFiles cmdops.Folder \"*.*\" cmdops.Recursive, fun name -&gt;\r\n             let file = new FileInfo(name)\r\n             if(Regex.IsMatch(file.Name, cmdops.Pattern, RegexOptions.Singleline)) then\r\n                let filename = file.Name.Substring(0, file.Name.LastIndexOf('.'))\r\n                let newname = file.Directory.FullName+\"\\\\\"+cmdops.Prefix+filename+cmdops.Suffix+file.Extension\r\n                System.IO.File.Move(file.FullName, newname)\r\n                printfn \"%s -&gt; %s\" file.FullName newname)\r\n       with e -&gt; printfn \"%s\" e.InnerException.Message\r\n  \r\n   Console.WriteLine(\"Press any key to continue...\")\r\n   Console.ReadKey()\r\n  \r\nmain()\r\n<\/pre>\n<p>Of course, the options available in this application (on file name changes) are pretty limited, but that can be extended at will.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I&#8217;ll show some F# constructs, all put together in a simple application that modifies file names that match a criteria. This would be an application that is started from a console with the following command line options: filesmod.exe -f &lt; folder &gt; [-r] -p &lt; pattern &gt; [-pre &lt; prefix &gt;] [-suf &#8230; <a title=\"Applying File Transformations with F#\" class=\"read-more\" href=\"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/\" aria-label=\"Read more about Applying File Transformations with F#\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[37,42],"tags":[43,47,46,45,44,48],"class_list":["post-121","post","type-post","status-publish","format-standard","hentry","category-fsharp","category-parallel-programming","tag-files","tag-parallel","tag-pattern","tag-record","tag-recursive","tag-regex"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"files,parallel,pattern,record,recursive,regex\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Applying File Transformations with F#\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2008-05-06T20:10:57+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2008-05-06T20:14:00+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Applying File Transformations with F#\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/05\\\/06\\\/applying-file-transformations-with-f\\\/#article\",\"name\":\"Applying File Transformations with F#\",\"headline\":\"Applying File Transformations with F#\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"datePublished\":\"2008-05-06T15:10:57+02:00\",\"dateModified\":\"2008-05-06T15:14:00+02:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/05\\\/06\\\/applying-file-transformations-with-f\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/05\\\/06\\\/applying-file-transformations-with-f\\\/#webpage\"},\"articleSection\":\"F#, Parallel Programming, files, parallel, pattern, record, recursive, regex\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/05\\\/06\\\/applying-file-transformations-with-f\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"name\":\".NET\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"position\":4,\"name\":\".NET\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/fsharp\\\/#listItem\",\"name\":\"F#\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/fsharp\\\/#listItem\",\"position\":5,\"name\":\"F#\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/fsharp\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/05\\\/06\\\/applying-file-transformations-with-f\\\/#listItem\",\"name\":\"Applying File Transformations with F#\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/#listItem\",\"name\":\".NET\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/05\\\/06\\\/applying-file-transformations-with-f\\\/#listItem\",\"position\":6,\"name\":\"Applying File Transformations with F#\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/net\\\/fsharp\\\/#listItem\",\"name\":\"F#\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/05\\\/06\\\/applying-file-transformations-with-f\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/05\\\/06\\\/applying-file-transformations-with-f\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/05\\\/06\\\/applying-file-transformations-with-f\\\/\",\"name\":\"Applying File Transformations with F#\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2008\\\/05\\\/06\\\/applying-file-transformations-with-f\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2008-05-06T15:10:57+02:00\",\"dateModified\":\"2008-05-06T15:14:00+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Applying File Transformations with F#","description":"","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/","robots":"max-image-preview:large","keywords":"files,parallel,pattern,record,recursive,regex","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/#article","name":"Applying File Transformations with F#","headline":"Applying File Transformations with F#","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"datePublished":"2008-05-06T15:10:57+02:00","dateModified":"2008-05-06T15:14:00+02:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/#webpage"},"articleSection":"F#, Parallel Programming, files, parallel, pattern, record, recursive, regex"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","name":".NET"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","position":4,"name":".NET","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/fsharp\/#listItem","name":"F#"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/fsharp\/#listItem","position":5,"name":"F#","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/fsharp\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/#listItem","name":"Applying File Transformations with F#"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/#listItem","name":".NET"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/#listItem","position":6,"name":"Applying File Transformations with F#","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/fsharp\/#listItem","name":"F#"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/","name":"Applying File Transformations with F#","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2008-05-06T15:10:57+02:00","dateModified":"2008-05-06T15:14:00+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"Applying File Transformations with F#","og:url":"https:\/\/mariusbancila.ro\/blog\/2008\/05\/06\/applying-file-transformations-with-f\/","article:published_time":"2008-05-06T20:10:57+00:00","article:modified_time":"2008-05-06T20:14:00+00:00","twitter:card":"summary","twitter:title":"Applying File Transformations with F#"},"aioseo_meta_data":{"post_id":"121","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:13:46","updated":"2025-12-12 07:19:10","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"In this post I&#8217;ll show some F# constructs, all put together in a simple application that modifies file names that match a criteria. This would be an application that is started from a console with the following command line options: filesmod.exe -f &lt; folder &gt; [-r] -p &lt; pattern &gt; [-pre &lt; prefix &gt;] [-suf&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/net\/fsharp\/\" class=\"advgb-post-tax-term\">F#<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/parallel-programming\/\" class=\"advgb-post-tax-term\">Parallel Programming<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">F#<\/span>","<span class=\"advgb-post-tax-term\">Parallel Programming<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/parallel-programming\/\" class=\"advgb-post-tax-term\">files<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/parallel-programming\/\" class=\"advgb-post-tax-term\">parallel<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/parallel-programming\/\" class=\"advgb-post-tax-term\">pattern<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/parallel-programming\/\" class=\"advgb-post-tax-term\">record<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/parallel-programming\/\" class=\"advgb-post-tax-term\">recursive<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/parallel-programming\/\" class=\"advgb-post-tax-term\">regex<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">files<\/span>","<span class=\"advgb-post-tax-term\">parallel<\/span>","<span class=\"advgb-post-tax-term\">pattern<\/span>","<span class=\"advgb-post-tax-term\">record<\/span>","<span class=\"advgb-post-tax-term\">recursive<\/span>","<span class=\"advgb-post-tax-term\">regex<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 18 years ago","modified":"Updated 18 years ago"},"absolute_dates":{"created":"Posted on May 6, 2008","modified":"Updated on May 6, 2008"},"absolute_dates_time":{"created":"Posted on May 6, 2008 3:10 pm","modified":"Updated on May 6, 2008 3:14 pm"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-1X","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=121"}],"version-history":[{"count":0,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/121\/revisions"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}