⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 path.h

📁 从各种控件中获得数据 自动生成XML文档 并通过XSLT转换为其他形式的XML文档
💻 H
字号:
//////////////////////////////////////////////////////////////////////
//	Implemented by Samuel Gonzalo 
//
//	You may freely use or modify this code 
//////////////////////////////////////////////////////////////////////
//
// Path.h: interface for the CJohnSplitPath class.
//
//////////////////////////////////////////////////////////////////////
#pragma once
//#include "mis_comm_ver.h"

#include <afxtempl.h>

const char	sCEmptyString = 0x0;
enum		{PATH_CMDLINE, PATH_MODULE};
enum		{FILE_CREATION, FILE_ACCESS, FILE_WRITE};

class/* _MIS_COMMON_API*/ CJohnSplitPath  
{
public:
	CJohnSplitPath();
	CJohnSplitPath(LPCTSTR szPath, BOOL bIsFolderPath = FALSE, BOOL bHasArguments = FALSE);
	CJohnSplitPath(DWORD dwSpecial);
	virtual ~CJohnSplitPath();

	// Parses a path or PATH_CMDLINE, PATH_MODULE
	void	SetPath(LPCTSTR szPath, BOOL bIsFolderPath = FALSE, BOOL bHasArguments = FALSE);
	void	SetPath(DWORD dwSpecial);
	CString	GetPath(BOOL bAppendArgs = FALSE, BOOL bOriginal = FALSE);
	CString	GetShortPath();
	CString	GetLongPath();

	BOOL IsLocalPath();
	BOOL IsRelativePath();
	BOOL IsFilePath();

	BOOL ExistFile();
	BOOL ExistLocation();


	// If the path set in the object is not a relative one returns empty
	CString	GetAbsolutePath(LPCTSTR szBaseFolder);

	// If the path set in the object is a relative one returns empty
	CString	GetRelativePath(LPCTSTR szBaseFolder);


	// Get drive string (empty for a network path) [e.g.: "c:"]
	CString	GetDrive();

	// Get drive label (pc name for a network path) [e.g.: "MAIN_HD"]
	CString	GetDriveLabel(BOOL bPCNameIfNetwork = FALSE);

	// Get folder count in path [e.g.: 2 for "c:\folder\subfolder\file.ext"]
	int		GetDirCount();

	// Get 0 based nIndex folder string [e.g.: "folder" for nIndex = 0]
	// If nIndex = -1 the return string is the full dir string 
	// [e.g.: "\folder\subfolder\" or "\\pcname\folder\" for non-local]
	// If it's a relative path no "\" is added at the beginning [e.g.: "..\sub\"]
	CString	GetDir(int nIndex = -1);

	// File location or directory path [e.g.: "c:\folder\subfolder\"]
	CString	GetLocation();

	// File title string (without extension) [e.g.: "file" for "..\file.ext"]
	CString	GetFileTitle();

	// Filename = File title + extension [e.g.: "file.ext"]
	CString	GetFileName();

	// Extension string (dot included) [e.g.: ".ext"]
	CString	GetExtension();

	// Extension name (dot not included) [e.g.: "ext"]
	CString	GetExtName();

	// Get argument count [e.g.: 2 for <c:\app.exe param1 "param 2">]
	int		GetArgCount();

	// Get 0 based nIndex argument string
	// If nIndex = -1 the return string is the argument part of the path
	// if bGetFlag is true, return the 0 based nIndex argument flag
	CString	GetArgument(int nIndex = -1, BOOL bGetFlag = FALSE);

	// Set the arguments for the current file path
	void	SetArguments(LPCTSTR szArgs);

	// Add or set an argument
	void	AddSetArgument(LPCTSTR szFlag, LPCTSTR szArgument);

	// Remove argument nIndex
	void	RemoveArgument(int nIndex);

	// Return 0 based index of the argument whose flag matches szFlag
	// If it's not found, the return value is -1
	int		FindArgument(LPCTSTR szFlag);


	// Get the size in bytes of the current file
	BOOL	GetFileSize(__int64 &nSize);

	// Get the size in bytes of the current file
	// values: FILE_CREATION, FILE_ACCESS, FILE_WRITE
	BOOL	GetFileTime(CTime &time, DWORD dwType = FILE_WRITE);


	// Return a temporary character pointer to the path data.
	operator LPCTSTR ();

	// Same as SetPath(szPath, FALSE, FALSE)
	const CJohnSplitPath& operator = (LPCTSTR szPath);

	// Makes a copy of the object
	const CJohnSplitPath& operator = (CJohnSplitPath &ref);

	// Add a back slash ('\' or '/' if bInverted is TRUE) if necessary
	static CString AddBackSlash(LPCTSTR szFolderPath, BOOL bInverted = FALSE);

	// Removes a trailing back slash if found
	static CString RemoveBackSlash(LPCTSTR szFolderPath);

private:
	void FillDirArray();
	void FillArgArray();
	BOOL FillFileInfoStruct();

	CString			_sOriginalPath;

	CString			_sDrive;
	CString			_sDriveLabel;
	CStringArray	_aDir;
	CString			_sDir;
	CString			_sFileTitle;
	CString			_sExtName;

	class CArgument
	{
	public:
		CArgument() 
		{ cFlagMark = '/'; }
		virtual ~CArgument() {}

		CString GetString()
		{
			CString sArg;
			if (!sFlag.IsEmpty()) sArg.Format(" %c%s", cFlagMark, sFlag);
			if (!sValue.IsEmpty())
			{
				if (sValue.Find(' ') != -1)
					sArg += CString(" \"") + sValue + CString("\"");
				else
					sArg += CString(" ") + sValue;
			}

			return sArg;
		}

		void SetFlag(CString sFlagValue)
		{
			sFlag = sFlagValue;
			if (sFlag.Remove('/') > 0) cFlagMark = '/';
			if (sFlag.Remove('-') > 0) cFlagMark = '-';
			sFlag.Remove(' ');
		}

		char	cFlagMark;
		CString	sFlag;
		CString	sValue;
	};

	typedef CArray<CArgument, CArgument&> ATArguments;

	CString			_sArgs;
	ATArguments		_aArgs;

	BOOL			_bIsRelative;

	BY_HANDLE_FILE_INFORMATION _fis;

	CString			_sLPCTSTRPath;
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -