Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Monday, October 13, 2008

Powershell: Process contents of Directory

Hello!  I know it has been a while since I posted any thing.  I have been busy working on a lot of different projects and I picked up a second job so that has been keeping me busy as well.  

Todays post is mostly some powershell code to process Microsoft Document Imaging Files (.mdi or .tif) and converting them to PDF's using a program called MDI2PDF from Bugysoft.  

Part of our specific problem is these files are really Microsoft Document Imaging Files but they have the .tif file extenstion.  We wrote a PHP script to process all of our uploads from the one client that sends us these files and based on some tests we put the MDI Files into a specific directory for processing.

And now on to the Code.  Lines that start with a # are comments for explaining what each line / section does.

#Setting up variables for our use
         $input = "y:\allAuths\problemAuths\"
         $output = "y:\allAuths\processAuths\"
         $convert = "C:\Program Files\MDIConvertor\MDI2PDF.exe"

#Get the current number of errors present in the global $error variable.
     $olderrorcount = $error.count

#Check to see if MDI2PDF is running. If it is this script will fail, so we need to kill it.
       $proclist = get-process mdi2pdf -ea silentlycontinue

#If the number of errors is the same as is used to be then we can kill the running process(es).  Otherwise we have nothing to kill and continue on.
    if ($error.couint -eq $olderrorcount) {$proclist | stop-process}

#Here we get the contents of the input directory filtered for the type of file we want to convert.
      $filelist = get-childitem -Path $input -Filter *.tif

#For every file in our file list we need to run the following command in order from top to bottom.
     foreach ($file in $filelist)
     {
#Replaces the .tif with .pdf.
          $filename=$file -replace ($file.extension + "`$"),".pdf"

#Write something to the screen so the user knows something is happening.
       write-host "Converting $input$file"

#Look ma! Simple string concatenation!!!
#Roughly equal to &"C:\program files\mdiconvertor\mdi2pdf.exe export:y:\allauths\problemauths\.tif y:\allauths\processauths\.tif.pdf
         &$convert "export:$input$file $output$filename"

#get the process info for the currently running mdi2pdf process.
     $convertprocess = get-process mdi2pdf
#Wait for the process to exit before moving on to the next one. I used to use sleep 10 here but this is much better.
      $convertprocess.waitforexit()

#We need to check and make sure the converted file exists. If it does exist then we need to delete the original file.
    #variable to store the input filename. We will need this later to delete the file.
    $inputfile = $file.fullname
    #Variable to store the output filename and full path.  We use this later to check for its existance.
    $outputfile = $output + $filename
            #If the result of the path test is true we remove the file.
            if (test-path $outputfile)
            {remove-item $inputfile}
    }


Monday, May 14, 2007

Microsoft Visual Studio Express Editions Codename: "Orcas"

Microsoft recently release a Community Technical Preview (CTP) of it's next Visual Basic Express Edition (also C#, C++, and Web Developer). You can go to the Visual Studio Express Editions Codename: "Orcas" to see what they have changed in the new version(s).

I am currently downloading just the installs and not the MSDN Library, SQL Compact, or SQL Express Editions and it's over 870MB. I *MIGHT* update you when I have everything installed and working to see how my programs moved over and such.

**Please note there is also a patch to download if you are unfortunate and are running Windows Vista**

Thursday, May 10, 2007

Microsoft Silverlight Developer Reference

Quoted from www.silverlight.net
"Microsoft® Silverlight™ is a cross-browser, cross-platform plug-in for delivering the next generation of .NET based media experiences and rich interactive applications for the Web. Silverlight offers a flexible programming model that supports AJAX, VB, C#, Python, and Ruby, and integrates with existing Web applications. Silverlight supports fast, cost-effective delivery of high-quality video to all major browsers running on the Mac OS or Windows."

And here is a Developer Reference that you can print out to use while programming in this new framework.

Tuesday, December 12, 2006

Touch for Windows ported to VB.net

Well I had some free time today and ported touch to VB.net. It was way easier than I thought it would be. I get the feeling that porting between C# & VB.net is not that hard (as there are online tools that can do it for you) but it was a good experiance anyways.

You can download Touch for Windows here. It is released under the GPL as was the C# version by Johan Cyprich of Cyprich.com. The source code can be found here.

I also plan on adding more of the features of the *nix touch program in the future. Check back later for updates.

Friday, December 08, 2006

Touch 2.00

This is an update to my previous post "Touch for Windows". Johan now has a handy installer and rewritten Touch in C#. To top everything off he has also released the code for Touch 2.00 so you can make changes / improvements. I might take a look and see if I can port this over to VB.Net 2005 as well. Below is an excerp from his site http://www.cyprich.com/.

"This utility can set the date and time of a file. It was originally written in Visual C++ and has been ported to C#. The source code is included.
I wrote this program mainly to show how easy it is to set the date and time of a file. I’ve seen overly complicated ways of programming touch and this source should show how simple it is with .NET 2.0.
You can get the file by clicking here."