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.
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. 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:
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. Important Things to Note:
Creo4GrabLatestFiles.ps1
3 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?
Reply
Your comment will be posted after it is approved.
Leave a Reply. |
AuthorErick Johnson Archives
May 2024
Categories
All
|