Erick's Blog
  • Home
  • Blog
  • Apps
    • Mortgage Calculator
  • PowerShell
    • Blog & Examples
    • Excel Reference
  • Windchill
    • Document Exporter
    • Document Worker
    • E.P.L.E.S.
    • Export Released
    • Property Checker
    • Windchill Business Analytics >
      • Part 01 - Program Logic
      • Part 02 - Getting Data with SQL Queries
      • Part 03 - Automating SQL Queries
      • Part 04 - Converting SQL Results to XML
      • Part 05 - Data Processing and Manipulation
      • Part 06 - Displaying XML in HTML
      • Part 07 - Auto Updating Displayed Data
      • Part 08 - Hosting Webpage with an Existing Apache Installation
      • Part 09 - Running Multiple Queries In Sequence
      • Part 10 - Calculating Data Trends
      • Part 11 - Making It Modular
    • Windchill Quick View
  • Reviews
  • Music
  • Contact

Creo 4.0 and PowerShell - Part 5: Finding the Latest Creo Files

7/17/2017

2 Comments

 
Picture
Hello again Creo+PowerShell Followers!

Are you one of those Creo people or know one who leaves their files all over the place?  Do you find it impossible and frustrating when trying to locate a file to work on?  I may have the solution for you!

Today, I am going to show you a fairly simple script that will locate the latest copy of each uniquely named Creo file and copy it to a user-defined folder.  Take this as a chance to start over by having all of your files in the same location.  You can also use this script to see what folders contain Creo files if you want to make sure you have added all relevant search paths to your config.pro.
I want to start by saying that this script is simple PowerShell trickery and has nothing to do with the Creo API but it was made specifically for the purpose of working with Creo files in the ways I have stated above.  You can repurpose this script to work with other file types as well.

High Level Overview:
Here is a list of the major steps in the script.
  1. Find all folders which contain Creo files.
  2. Find all Creo files inside each folder.
  3. Compare Creo files with same name and only grab uniquely named files with the latest "Date Modified" attribute.
  4. Copy the latest files to a single folder.

Finding All Folders with Creo Files (findCreoFilePaths Function):
The script will automatically detect all drives and mapped drives on your computer.  You can and need to manually add any network locations to the $networkLocations array in order to include those directories.  Starting from these paths, the script will recursively search all folders and subfolders for Creo files.  I have only included .prt, .asm, and .drw but you can include additional file extensions.

A csv named "CreoFileLocations.csv" will be created showing all unique locations where such files were found.  Because this step is the most time consuming, I have include a way to include an existing "CreoFileLocations.csv" from a previous run to speed up additional runs.  Make sure to set $useExistingCreoFileLocationsCSV = $true in order to use this feature.
Picture
CSV Output of findCreoFilePaths Function

Finding All Latest Creo Files (findLatestCreoFiles Function):
Now that we have all the paths where Creo files exist, it makes the rest of the script much faster.  We will no longer recursively search these paths as we already have the exact path of Creo files.  For each path found, the script will:
  1. Get a list of Creo files in that directory.
  2. Compare the filename with all other found files.
  3. Compare the Date Modified attribute against all other files with the same filename.
  4. Populate the $latestFilesArray with the file that has the latest Date Modified attribute.
  5. Create "LatestCreoFiles.csv" in given $csvLocation with file information.
Picture
CSV Output of findLatestCreoFiles Functions

Copying All Latest Creo Files to Specified Folder Location (copyLatestCreoFiles Function):
Now that we have a list of the latest Creo files, we can easily iterate through it and copy each file to a single location.  Once the copy is complete, a CSV named "CreoFileCopyResults.csv" will display the copy status of each file confirming whether or not the copies were successful.  You would just need to add this single folder to your Creo search path going forward if you do indeed have all the files you need.

Script Logging:
Although the script doesn't have full error checking, there is some basic logging to help you identify points where issues occur.  Below is an example of a successful run of the script.
Picture
Script Log Output

Important Things to Note:
  • This script doesn't check if files are truly unique i.e. via hash check.  The script only looks at filename and date modified.  It assumes files with the same filename must be related files which are either the same or a older/newer version.
  • It is important that if you choose to use this script, that you give it all the possible locations where Creo files may be i.e. fill out $networkLocations array.
  • You should erase all of your Creo Search Paths and add only the path to the folder where the latest files were copied in order to avoid any issues with using the wrong files later on.
  • There may be other issues that I can't see or haven't seen so you should test this in a controlled environment first.
  • If you notice any issues with my code, please comment below so everyone else may see what needs to be changed.
  • If you like the script and want to see more, please comment below.

​Creo4GrabLatestFiles.ps1

    
2 Comments
Branden
12/13/2017 10:27:34 am

This looks like exactly what we need. We have creo 1.0 and no windchill. Thinking of giving this a shot soon. Hopefully it isnt too rough.

Reply
Mitja
1/7/2021 06:20:07 am

Hi! Your script is really nice. I have a following a problem..I copied all files in a single folder on the desktop. It has cca. 50k files. PowerShell script runs indefinitely without "solution". Are there any limitations for such application? Can script be optimized so that only specific folder is checked?

Regards.
Mitja

Reply



Leave a Reply.

    Author

    PLM engineer while "on the clock", programmer, designer, dreamer all other times.

    Archives

    July 2017
    May 2017
    February 2017
    January 2017
    December 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016

    Categories

    All
    ASP.NET
    Batch Script
    C#
    Career
    Computers
    Creo
    Creo API
    Flash
    GameMaker
    GitHub
    Home Loan
    How To
    HTML5
    Java
    JavaScript
    MAME
    Mortgage
    Music
    .NET Core
    Office
    PC Games
    PfSense
    PowerShell
    Reviews
    Robot
    SQL
    Video Games
    Web App
    Windchill
    Windchill API

    RSS Feed

Copyright © 2018 Erick Johnson
  • Home
  • Blog
  • Apps
    • Mortgage Calculator
  • PowerShell
    • Blog & Examples
    • Excel Reference
  • Windchill
    • Document Exporter
    • Document Worker
    • E.P.L.E.S.
    • Export Released
    • Property Checker
    • Windchill Business Analytics >
      • Part 01 - Program Logic
      • Part 02 - Getting Data with SQL Queries
      • Part 03 - Automating SQL Queries
      • Part 04 - Converting SQL Results to XML
      • Part 05 - Data Processing and Manipulation
      • Part 06 - Displaying XML in HTML
      • Part 07 - Auto Updating Displayed Data
      • Part 08 - Hosting Webpage with an Existing Apache Installation
      • Part 09 - Running Multiple Queries In Sequence
      • Part 10 - Calculating Data Trends
      • Part 11 - Making It Modular
    • Windchill Quick View
  • Reviews
  • Music
  • Contact