FileMove not working - FileDelete and FileAppend working normally Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Pterocles
Posts: 5
Joined: 08 Sep 2017, 14:24

FileMove not working - FileDelete and FileAppend working normally

16 Apr 2019, 13:37

I'm writing a script that detects newly-scanned documents and archives them in a public directory (R:), but I've hit a brick wall and have narrowed it down to FileMove not working at all.

I can manually create and modify documents in both the source and destination folders, and the file I'm trying to move is not read-only. Oddly, while FileCopy doesn't work either, my script successfully uses FileDelete and FileAppend on a text file in the source folder for storing variables between runs.

The following is not the main script, but that is the source and destination I'm trying to move between. This does NOT work on my system, and A_LastError is set to 3 - which is Windows for ERROR_PATH_NOT_FOUND. However, the FileDelete at the end works exactly as expected.

Code: Select all

#SingleInstance Force
#Persistent
#NoEnv

Source := "C:\Users\khigby\Documents\Purgatory\TEMP-190416-001.pdf"
DestA := "R:\Receipts\Integricoat\42727\28242.pdf"
DestB := "C:\Users\khigby\Documents\Receipt Archive\TEMP-190416-001.pdf"

FileSetAttrib,-R,%Source% ;Make sure the file is writable.

Try
	FileMove, %Source%, %DestA%
Catch {
	Try
		FileMove, %Source%, %DestB%
	Catch
		MsgBox All is lost. Your dreams are dead. Abandon hope.
}
FileDelete, %Source%
Return
Pterocles
Posts: 5
Joined: 08 Sep 2017, 14:24

Re: FileMove not working - FileDelete and FileAppend working normally  Topic is solved

16 Apr 2019, 14:29

... I figured it out.

FIleMove will not create new directories - the destination must be an existing directory. This is not specified in the documentation, nor is it implied.

I can use FileCreateDir to create the folder structure I want in the archive, then FileMove the PDF into it.

The documentation for FileMove should be updated to reflect this limitation. It's not obvious, since FileAppend will create directories that don't yet exist.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Bing [Bot], leehere10, Xeo786 and 33 guests