对照Windows的命令行参考,写了个Find命令的例子,怎么运行也通不过。

总是报No such file and directory。大惑不解,在别人机子上测试通过,而我在公司和宿舍的机子上都测试通不过,这才想到可能是环境设置的问题。明确的把Find.exe声明为C:\WINDOWS\system32\find.exe,哈哈测试通过。

说明我的环境变量Path中前面有一个同名的Find.exe把system32的Find.exe给覆盖了。一个个的找啊找,发现是MSYS惹的祸,这个名字设计的真不太好。

解决办法把System32的路径写在MSYS的前面,如果要使用MSYS的Find,只好写个bat批处理临时改变环境变量了。

附命令行参考文档路径(Windows XP)
C:\WINDOWS\Help\ntcmds.chm
相对上网找一些支离破碎的文章,有一份全面且官方的资料一定会更好吧

说的比较绕,不过应该能表达意思。前阵写了个脚本,心里想着有时间做个工具,刚刚发现PsPad居然已经内置了这个功能,真是贴心哪。查找替换功能要比Emeditor, Notepad++好很多啊。
心里感触,做什么事情千万不要一成不变,不要说用习惯了Notpad++就一直不尝试新工具,多调查哪个工具有什么优点,什么情况用最适合的工具才能节省时间精力。
选工具是这样,开发时选框架同样,没有最好,选取对完成该工作最合适的。而不是因为自己会Java,所以选Java,会PHP所以工程就用PHP。

看到有人用Dos命令写,看了看For指令头晕。于是用WSH脚本写一个,忙活完了发现不支持UTF-8。
WSH的FSO只支持ANSI,UTF-16,ASCII三种编码…

下面是代码了,保存为.wsf后缀双击运行。extensionReg是文件后缀的正则表达式,replacePair是替换规则。
replacePair可以包含多个替换,每个替换是一个数组元素,也是一个对象,此对象reg属性是匹配规则,str属性是要替换的字条串。

<job id="main">
<script language="JScript">
	// Note: This script will not function correctly with non-ANSI Encoding files.
	// ################################    Settings   ####################### /
	// File's extension
	var extensionReg = /^.+\.(xml|txt)$/ig;
	// Replace rules
	// The replacePair Array contains multiple replacement rule objects.
	// Each object contains reg and str property.
	// The reg property is a Regular Expression
	// and the str property replaces every successful match of reg.
	var replacePair = [{reg:/\[^<>]*\<\/value\>/ig, str:"###value###"},
						{reg:/\[^<>]*\<\/label\>/ig, str:"###label###"}];
	// ####################################################################### /
	// Constant
	var WshShell = WScript.CreateObject("WScript.Shell");
	var ForReading = 1, ForWriting = 2, ForAppending = 8;
	var ANSI = -2, UTF-16 = -1, ASCII = 0;
	var fso = new ActiveXObject("Scripting.FileSystemObject");

	// Current Folder
	var curFolder = fso.GetFolder(WshShell.CurrentDirectory);
	// iterator of Files in the current folder
	var fc = new Enumerator(curFolder.files);
	var counter = 0;
	// loop though files
	for (; !fc.atEnd(); fc.moveNext())
	{
		var file = fc.item();
		var fileName = file.Name;
		// test of file name match
		if (fileName.search(extensionReg) == -1)
			continue;
		var content = readAllFromFile(file.Path);
		var contentRet = content;
		var pc = new Enumerator(replacePair);
		for (; !pc.atEnd(); pc.moveNext()) {
			var replaceItem = pc.item();
			contentRet = contentRet.replace(replaceItem.reg, replaceItem.str);
		}
		if (contentRet != content) {
			writeStrToFile(file.Path, contentRet);
			++counter;
		}
	}
	// Show the result with OK button and "Information Mark" icon.
	WshShell.Popup(counter + " files has been replaced.", 0, "Result", 0 + 64);

	function readAllFromFile(path) {
		var ret = "";
		var ts = fso.OpenTextFile(path, ForReading, false, ANSI);
		if (!ts.AtEndOfStream)
			ret = ts.ReadAll();
		ts.Close();
		return ret;
	}

	function writeStrToFile(path, str) {
		var ts = fso.OpenTextFile(path, ForWriting, true, ANSI);
		ts.Write(str);
		ts.Close();
	}

	// Debug
	function trace(msg) {
		WScript.Echo(msg);
		WScript.Quit();
	}
</script>
</job>

如果TabNavigator的selectedIndex没有效果,那么你可能遇到Flex的一个Bug。

参考:http://bugs.adobe.com/jira/browse/SDK-15974

Eric Belair,the reporter shows us a way out.

package jp.co.nis.swf.component
{
	import mx.containers.TabNavigator;

	public class FixedTabNavigator extends TabNavigator
	{
		override protected function commitSelectedIndex(newIndex:int) : void
		{
			super.commitSelectedIndex(newIndex);
			// Correct the selectedIndex in the tabBar.
			tabBar.selectedIndex = newIndex;
		}
	}
}

I often connect to my blog’s mysql host, do some query, and delete comment spams. At first I used a UI mysql  administrator(mysql administrator and navicat), but I found it so slowly and I could not bear it.

So I changed to use command line, it became fast immediately. But typing the command everytime is tired, you could use the following windows script to do this automatically.

<job id="main">
<script language="JScript">
	var WshShell = WScript.CreateObject("WScript.Shell");
	WshShell.Run("cmd.exe");
	WScript.Sleep(500);
	WshShell.AppActivate("cmd.exe");
	WScript.Sleep(200);
	WshShell.SendKeys ("mysql -h ip_address -u user_name -p{ENTER}");
	WScript.Sleep(500);
	WshShell.SendKeys ("password{ENTER}");
	WScript.Sleep(5000);
	WshShell.SendKeys ("use your_schema{ENTER}");
	WScript.Sleep(3000);
	// WshShell.SendKeys ("show tables;{ENTER}");
	// WScript.Sleep(4000);
	WshShell.SendKeys ("delete from wp_comments where comment_author_ip = \'194.8.75.149\';{ENTER}");
	WScript.Sleep(2000);
	WshShell.SendKeys ("delete from wp_comments where comment_author_ip = \'66.232.103.247\';{ENTER}");
	WScript.Sleep(2000);
	WshShell.SendKeys ("delete from wp_comments where comment_author_ip = \'194.8.75.163\';{ENTER}");
	WScript.Sleep(2000);
	WshShell.SendKeys ("quit{ENTER}");
</script>
</job>

现在即使是自己一个人开发也已经离不开版本管理工具了,没有版本管理很不方便。
在自己机子上建个SVN Repository自己用。
安装TortoiseSVN后一切变得超简单,在一个空目录右键TortoiseSVN–>Create Repository Here搞定。本地访问版本库使用file:///D:/SVNRepository/这样的URL就可以了,在局域网还可以把此目录共享,使用file://ServerName/path/to/repos/连接版本库。
如果不只是局域网使用,那么建个Apache Server吧(TortoiseSVN Help — Setting up a server — Apache Based Server),或者干脆使用Google Code有点慢。

Powered by WordPress

ֻҡƵ졡