Create Shortcut Using Batch Script in Windows

shotcut.bat

@echo off
 
call :create_shortcut "Z:\port\d\7-Zip\"	7zFM.exe	C:\Users\eu\Desktop\ 7z
 
pause
exit
 
:create_shortcut
	set src_dir=%1%
	set src_file=%2%
	set dst_dir=%3%
	set dst_file=%4%
 
	echo "%src_dir%%src_file% => %dst_dir%%dst_file%"
 
	shotcut_func.vbs %src_dir% %src_file% %dst_dir% %dst_file%

	rem echo [InternetShortcut] >> %shortcut%
	rem echo URL="%source%" >> %shortcut%
	rem echo IconFile=%source% >> %shortcut%
	rem echo IconIndex=20 >> %shortcut%

shotcut_func.vbs

src_dir = wscript.arguments(0)
src_file = wscript.arguments(1)
dst_dir = wscript.arguments(2)
dst_file = wscript.arguments(3)
 
Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = dst_dir + dst_file + ".lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
 
oLink.TargetPath = src_dir + src_file
' optional shortcut properties
' oLink.Arguments = ""
' oLink.IconLocation = src_dir + src_file + ", 2"
' oLink.WindowStyle = "1"
oLink.WorkingDirectory = src_dir
oLink.Save

refresh_icons.bat

taskkill /f /im explorer.exe
 
attrib -h -s -r "%userprofile%\AppData\Local\IconCache.db"
del /f "%userprofile%\AppData\Local\IconCache.db"
attrib /s /d -h -s -r "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\*"
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_32.db"
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_96.db"
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_102.db"
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_256.db"
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_1024.db"
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_idx.db"
del /f "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\thumbcache_sr.db"
 
echo y | reg delete "HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify" /v IconStreams
echo y | reg delete "HKEY_CLASSES_ROOT\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify" /v PastIconsStream
 
start explorer

refer to:
https://serverfault.com/questions/171775/create-a-windows-shortcut-through-a-batch-file-bat
https://wenwen.sogou.com/z/q813141367.htm
https://www.2cto.com/kf/201307/225348.html
https://zhuanlan.zhihu.com/p/72426926

Re-compress all Mame zip roms to 7z format

In advance,

trans_to_7z.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
 
PARENTDIR=$1
TMPDIR=`pwd`/tmp
 
PATH="/d/cext/Program Files/7-Zip:$PATH"
 
ISERR="no"
 
if [ "x$1" = x ] ; then
	echo "Please input dir to transform."
	exit
fi
 
if [ -e "$TMPDIR" ] ; then
	echo "Please rmdir [$TMPDIR] first."
	exit
fi
 
get_win_path()
{
	local win_path="$1"
	win_path="${win_path#/}"
	win_path="${win_path//\//\\}"
	win_path="${win_path/\\/\:\\}"
	echo $win_path
}
 
format_transform()
{
	local file_7z=$1
	local file_zip=$2
	local tmp_dir=$TMPDIR
	mkdir "$tmp_dir"
 
	7z x ${file_7z} -o"`get_win_path \"$tmp_dir\"`"
	(
		cd "$tmp_dir"
		ls
 
		7z a -mx9 "`get_win_path \"${file_zip}\"`" || ( echo "Creating 7z file failed." && ISERR="yes" )
	)
 
	rm -Rf "$tmp_dir"
}
 
cd "$PARENTDIR"
 
for fn in `ls *.zip`; do
 
	echo "$fn"
 
	format_transform $fn "`pwd`/${fn%.zip}.7z"
 
	if [ $ISERR = "yes" ]; then
		exit
	fi
done
 
echo "Transforming done."

How to use?

Copy trans_to_7z.sh to Mame root folder which contains roms sub-directory, right click at blank place of this Mame root window in Explorer, select "Git Bash Here" which prompts bash console, input below and return,

1
./trans_to_7z.sh roms

refer to:
https://www.cnblogs.com/wq242424/p/15564203.html

用curl发送json请求

以下是json.bat的内容:

1
2
3
4
set /P json=<%1
set result=%json:"=\"%
curl -H "Content-Type:application/json" -X POST -d %result% http://you.url
pause

然后把只含json内容的文件拖到json.bat上面运行就可以了。

注意1,我测试时下载的curl命令行工具是不支持json串中包含空格的,这里只作测试用途,空格先都去掉。
注意2,json.bat第2行包含了Windows批处理脚本中,往字符串里插入字符的方法,此处是把json字符串中每一个双引号前插入一个反斜杠。