FileMove 重命名不生效 Topic is solved

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: tmplinshi, arcticir

shouyoubetter

FileMove 重命名不生效

12 Mar 2023, 10:28

Code: Select all

Log(ByRef str, rn=1)
{
	DllCall("AllocConsole"), rn:=(rn ? "`r`n":"")
	FileAppend, %str%%rn%, *
}
; 关闭控制台(手动关闭会退出AHK程序)
logoff()
{
	DllCall("FreeConsole")
}

typoraImgChangeName(){
	path:= "E:\笔记\spring\spring概述.md"
	SplitPath, path , OutFileName, OutDir, OutExtension, OutNameNoExt
	OutDir.="\" . OutNameNoExt . ".assets" . "\"
	title := ""
	titleIdx := 1
  oldfileList := []
  newfileList := []
  
	; While, flag
	Log("开始读取" . path)
	loop, Read, E:\笔记\spring\spring概述.md, E:\笔记\spring\spring概述2.md
	{
		newline := A_LoopReadLine
		;找到标题
		if(InStr(newline, "# ")){
			Array := StrSplit(newline , "# ")
			title := Array[2]
			Log(Array[2])
		}
		;找到图片
		if(InStr(newline, "![1")){
			;获取图片路径
			RegExMatch(newline, "\((.*)\)", fullName)

			; ![1676632803041](spring概述.assets/1676632803041.png)

			split:= StrSplit(fullName1, "/")
			mdFile:= split[1] . "/" . title . titleIdx . ".png"
			titleIdx += 1
			;重命名文件
			oldfile:= OutDir . split[2]
			newfile:= OutDir . title . titleIdx . ".png"
			Log(oldfile . " 移动到 ")
      Log(newfile)
      FileMove, oldfile, newfile
      Sleep, 3000
			oldfileList.Push(oldfile)
      newfileList.Push(newfile)
			newline:= StrReplace(newline, split[2], title . titleIdx . ".png")
		}
		FileAppend, %newline%`n
	}
	MsgBox "结束了"
}

typoraImgChangeName()

上面是我的代码 从Log打印出来的数据看 单独使用FileMove可以成功, 调用typoraImgChangeName就会失败
shouyoubetter

Re: FileMove 重命名不生效  Topic is solved

13 Mar 2023, 06:04

我找到问题所有在
FileMove, oldfile, newfile没有加%
换成FileMove, % oldfile, % newfile 即可

Return to “请求帮助”

Who is online

Users browsing this forum: No registered users and 15 guests