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

📄 mas.fs.js

📁 Full ARM920T S3C2443 ( Magellan Maestro 4245/4250 ) WinCE FileBackup of stored "Windows" path. Hope
💻 JS
📖 第 1 页 / 共 2 页
字号:

/**********************************************************************

FileSystem functions library for Majerus.net Active Shell CE
Copyright (C) 2006-2008 Majerus.net. All rights reserved. 
Script Name:	MAS.FS.js
Abstract:	Provides filesystem related functions to MAS.
Usage:		This creates an "fs" object containing many filesystem
		related methods.
		These methods can be used to provide interactive
		feedback in the console.

Requirements:	Microsoft does not provide the
		Scripting.FileSystemObject for Windows CE.
		Majerus.net Script Runtime provides this class for
		Windows CE and is required for this library.
		
Samples:	Load in MASX JScript using the following command:
		MAS> call(MASHome+"\\MAS.FS.js")
		MAS> fs.ver()
		MAS> fs.dir()
		
Warning:	This library is for sample purpose and is not intended
		to be of production quality.

**********************************************************************/

// WSH stub
if( typeof(MAS)=="undefined" ) { WScript.echo("This script requires Majerus.net Active Shell.\r\nIt can not be executed by the Windows Script Host"); WScript.quit(1); }

// Init global variables
var FSO;
try
{
	FSO = new ActiveXObject("Scripting.FileSystemObject");
}
catch (ex)
{
	MAS.Echo("The Scripting.FileSystemObject class is not installed.");
	MAS.Echo("This class is not part of Windows CE, you must install Majerus.net Script Runtime.");
}

// Converts DOS-style file and folder specs (using wildcards) to JScript regular expressions.
function FileSpec2RegExp(strFileSpec)
{
	if (strFileSpec != undefined)
		{
			strFileSpec = strFileSpec.replace(".","\\.");
			while (strFileSpec.indexOf("*")!=-1)
				strFileSpec = strFileSpec.replace("*", ".+");
			while (strFileSpec.indexOf("?")!=-1)
				strFileSpec = strFileSpec.replace("?", ".");
			return new RegExp( "^"+strFileSpec.toUpperCase()+"$" );
		}
	else
		return new RegExp(".*");
}

// Align a string to the right for a fixed width, using spaces padding.
function RightAlignString(str,count,chr)
{
	str = str.toString(); // convert to string in case we received another data type
	if (str.length > count)
		return str.substr(0,count-3)+"...";
	for (var i = str.length ; i < count ; i++)
		str = chr+str;
	return str;
}

// Align a string to the left for a fixed width, using spaces padding.
function LeftAlignString(str,count,chr)
{
	str = str.toString(); // convert to string in case we received another data type
	if (str.length > count)
		return str.substr(0,count-3)+"...";
	for (var i = str.length ; i < count ; i++)
		str += chr;
	return str;
}

// Add a method to the JScript Date class to get a short string representation for files lists.
function Date.prototype.toReportString()
{
	// Use US format "MM/DD/YYYY HH:MM"
	return (RightAlignString(this.getMonth()+1,2,"0") +"/"+ RightAlignString(this.getDate(),2,"0") +"/"+ this.getFullYear() +" "+
		RightAlignString(this.getHours(),2,"0") +":"+ RightAlignString(this.getMinutes(),2,"0"));
}

// Add a method to the JScript Number class to get a string representation for file sizes using multiplicators (bytes, KB, MB, GB).
function Number.prototype.toByteSizeString()
{
	var a = ["bytes","KB","MB","GB","TB"];
	var m = 0;
	var v = this;
	while ((v > 1024) && (m < a.length-1))
	{
		m++;
		v /= 1024;
	}
	return (v.toLocaleString() +" "+ a[m]);
}


// Display this component version information.
function _fs_ver()
{
	MAS.Echo();
	MAS.Echo ("MAS/CE FileSystem library version information");
	MAS.Echo ("- "+ MAS.Ver);
	MAS.Echo ("- "+ ScriptEngine() +" [Version "+ScriptEngineMajorVersion()+"."+ScriptEngineMinorVersion()+"."+ScriptEngineBuildVersion()+"]");
	MAS.Echo ("- FileSystemObject [Version "+FSO.GetFileVersion(FSO.BuildPath(FSO.GetSpecialFolder(1),"scrrun.dll"))+"]");
	MAS.Echo();
}

// CMD-like prompt, use it in global prompt function.
function _fs_prompt()
{
	if(
		(MAS.Location.Path.length <= (MAS.Cols/2))  // path takes less than half the console width
		|| (FSO.GetParentFolderName(FSO.GetParentFolderName(FSO.GetParentFolderName(MAS.Location.Path)))=="")  // or path depth is 3 or less folders
		)
	{
		// complete path prompt
		return MAS.Location + ">";
	}
	else
	{
		// current drive or share root and last 2 folders only
		return FSO.BuildPath(
			FSO.BuildPath( FSO.GetDriveName(MAS.Location.Path), "..."),
			FSO.BuildPath( FSO.GetFileName(FSO.GetParentFolderName(MAS.Location.Path)), FSO.GetFileName(MAS.Location.Path) )
			) + ">";
	}
}

// Get a Scripting.FileSystemObject Folder object for the current working folder.
function _fs_get_folder()
{
	return FSO.GetFolder(MAS.Location);
}

// Get a Scripting.FileSystemObject Files collection for files in the current working folder.
function _fs_get_files()
{
	return FSO.GetFolder(MAS.Location).Files;
}

// Get a Scripting.FileSystemObject Folders collection for folders in the current working folder.
function _fs_get_folders()
{
	return FSO.GetFolder(MAS.Location).SubFolders;
}

// List current working folder contents.
function _fs_dir(strFileSpec, bShowFoldersSizes)
{
	var colSep = "  ";
	var folder = FSO.GetFolder(MAS.Location);
	var filespec = FileSpec2RegExp(strFileSpec);
	
	Echo();
	Echo (" Directory: "+ folder.Path);
	Echo();
	
	// Headers
	var width = 16 + 15 + 15 + 3*colSep.length;
	Echo (
		LeftAlignString(	"Last Modified",			16," ") + colSep +
		RightAlignString(	"Size",					15," ") + colSep +
		LeftAlignString(	"Type",					15," ") + colSep +
		LeftAlignString(	"Name",					80-width," "));
	Echo (
		LeftAlignString(	"",					16,"-") + colSep +
		RightAlignString(	"",					15,"-") + colSep +
		LeftAlignString(	"",					15,"-") + colSep +
		LeftAlignString(	"",					80-width,"-"));
	
	var ts = 0; // total size
	
	// Subfolders
	var tsf = 0; // total subfolders
	var sf = new Enumerator(folder.SubFolders);
	for (sf.moveFirst() ; !sf.atEnd() ; sf.moveNext() )
	{
		var item = sf.item();
		if (item.Name.toUpperCase().match(filespec) != null)
		{
			Echo (
				LeftAlignString(new Date(item.DateLastModified).toReportString(),16," ") + colSep +
				RightAlignString(bShowFoldersSizes?item.Size.toByteSizeString():"",15," ") + colSep +
				LeftAlignString(item.Type,15," ") + colSep +
				LeftAlignString(item.Name,80-width," "));
			if (bShowFoldersSizes)
				ts += item.Size;
			tsf++;
		}
	}
	
	// Files
	var tf = 0; // total files
	var f = new Enumerator(folder.Files);
	for (f.moveFirst() ; !f.atEnd() ; f.moveNext() )
	{
		var item = f.item();
		if (item.Name.toUpperCase().match(filespec) != null)
		{
			Echo (
				LeftAlignString(new Date(item.DateLastModified).toReportString(),16," ") + colSep +
				RightAlignString(item.Size.toByteSizeString(),15," ") + colSep +
				LeftAlignString(item.Type,15," ") + colSep +
				LeftAlignString(item.Name,80-width," "));
			ts += item.Size;
			tf++;
		}
	}
	
	Echo();
	
	// Totals
	Echo (" "+
		tsf+" folder(s), "+
		tf +" file(s), "+
		ts.toByteSizeString() +" total");
}

// List attributes for files.
function _fs_attrib (strFileSpec)
{
	var attr = ["R","H","S","V"/*Volume*/,"D"/*Directory*/,"A","*"/*InRom*/,"N"/*Normal*/,"T"/*Temporary*/,"0"/*SparseFile*/,"\\"/*ReparsePoint*/,"C"/*Compressed*/,"O"/*Offline*/,"*"/*RomStaticRef*/,"*"/*RomModule*/,"E"/*Encrypted*/];
	var folder = FSO.GetFolder(MAS.Location);
	var filespec = FileSpec2RegExp(strFileSpec);
	
	var f = new Enumerator(folder.Files);
	for (f.moveFirst() ; !f.atEnd() ; f.moveNext() )
	{
		var file = f.item();
		if (file.Name.toUpperCase().match(filespec) != null)
		{
			var strA = "";
			var a = file.Attributes;
			var ai = attr.length;
			for ( i=Math.pow(2,attr.length) ; i>0 ; i=(i>1)?(i/2):0 )
			{
				if (a >= i)
				{
					a-=i;
					strA += attr[ai];
				}
				else
				{
					strA += " ";
				}
				ai--;
			}
			Echo (strA +"\t"+ file.Name);
		}
	}
}

// Execute CE commands scripts (CMD batch files).
function _fs_call (strFileSpec)
{
	var folder = FSO.GetFolder(MAS.Location);
	var filespec = FileSpec2RegExp(strFileSpec);
	
	var f = new Enumerator(folder.Files);
	for (f.moveFirst() ; !f.atEnd() ; f.moveNext() )
	{
		var file = f.item();
		if (file.Name.toUpperCase().match(filespec) != null)
		{
			var strExt = FSO.GetExtensionName(file.Name);
			if ((strExt == "cmd") || (strExt == "bat"))
				MAS.Exec("\\Windows\\cmd.exe /c \"" + file.Path + "\"");

⌨️ 快捷键说明

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