FileMove 重命名不生效

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: FileMove 重命名不生效

Re: FileMove 重命名不生效

Post by shouyoubetter » 13 Mar 2023, 06:04

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

FileMove 重命名不生效

Post by shouyoubetter » 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就会失败

Top