- Olbert_Utilities.zip
- Olbert.Utilities
- CryptorLib
- documentation
- bin
- Content Layout.content
- Creative Commons Attribution Share Alike.aml
- Cryptor Overview.aml
- GLPL.aml
- GPL.aml
- Licenses.aml
- Miscellaneous Utilities Overview.aml
- nHydrate Installer Overview.aml
- nHydrate Utilities.aml
- Olbert.Utils.shfbproj
- Open Source License v3.aml
- overview.aml
- Release Notes.aml
- Wizard Framework.aml
- WPF Utilities.aml
- MiscUtilities
- MiscUtilitiesCore
- nHydrateInstaller
- nHydrateUtils
- NotMine
- NotMineWPF
- OlbertUtilities.sln
- OlbertUtilities.suo
- WPFUtilities
- WPFWizard
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Olbert.Utilities
{
/// <summary>
/// a class of file utilities
/// </summary>
public static class FileUtils
{
// The TruncatePath method was posted by user Bigsby on the Microsoft social website and is presumably
// in the public domain. You can read more about it at
// http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0d0319ed-ea16-40c3-96c6-664b383b69cb/.
// Thanx, Bigsby!
/// <summary>
/// References a function in the lightweight shell library which intelligently truncates a file path.
/// </summary>
/// <param name="pszOut">the returned truncated path</param>
/// <param name="szPath">the path to truncate</param>
/// <param name="cchMax">the maximum number of characters allowed in the truncated path</param>
/// <param name="dwFlags">truncation flags (ignored)</param>
/// <returns>true if the conversion was successful, false otherwise</returns>
[DllImport("Shlwapi.dll", CharSet = CharSet.Unicode)]
static extern bool PathCompactPathEx( [Out] StringBuilder pszOut, string szPath, int cchMax, int dwFlags );
/// <summary>
/// Intelligently truncates a file path to the specified length
/// </summary>
/// <param name="path">the file path to truncate</param>
/// <param name="length">the maximum acceptable length</param>
/// <returns>a truncated file path</returns>
public static string TruncatePath( string path, int length )
{
StringBuilder sb = new StringBuilder(length + 1);
PathCompactPathEx(sb, path, length + 1, 0);
return sb.ToString();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Some people like to do crossword puzzles to hone their problem-solving skills. Me, I like to write software for the same reason.
A few years back I passed my 50th anniversary of programming. I believe that means it's officially more than a hobby or pastime. In fact, it may qualify as an addiction
.
I mostly work in C# and Windows. But I also play around with Linux (mostly Debian on Raspberry Pis) and Python.