FileMoveDir not moving folder contents Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SkipperBook3
Posts: 6
Joined: 18 Sep 2021, 09:18

FileMoveDir not moving folder contents

Post by SkipperBook3 » 18 Sep 2021, 09:23

Here is my script:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#Persistent
#SingleInstance Force

EnvGet, A_LocalAppData, LocalAppData
global A_LocalAppData := A_LocalAppData


ProcessExist(ProcessName)
{
	Process, Exist, %ProcessName%
	return ErrorLevel
}


;~ Close Discord gracefully if it is running
CloseDiscord()
{
	if ProcessExist("Discord.exe")
	{
		WinActivate, ahk_exe Discord.exe
		WinWaitActive, ahk_exe Discord.exe
		ControlSend,, {Alt down}{F4 down}{F4 up}{Alt up}, ahk_exe Discord.exe
		Process, WaitClose, Discord.exe
	}
}


RefreshTray()
{
	Menu, Tray, DeleteAll
	Menu, Tray, Add
	Loop, Files, %A_LocalAppData%\Programs\Discord account switcher\*, D
	{
		Menu, Tray, Add, %A_LoopFileName%, MenuHandler
	}
}


IfNotExist, %A_LocalAppData%\Programs\Discord account switcher
{
	FileCreateDir, %A_LocalAppData%\Programs\Discord account switcher\Account 2
	FileAppend, Account 1, %A_LocalAppData%\Programs\Discord account switcher\Active account.txt
}
RefreshTray()
return

MenuHandler:
CloseDiscord()
FileRead, ActiveAccount, %A_LocalAppData%\Programs\Discord account switcher\Active account.txt
FileMoveDir, %A_AppData%\Roaming\discord, %A_LocalAppData%\Programs\Discord account switcher\%ActiveAccount%
FileMoveDir, %A_LocalAppData%\Programs\Discord account switcher\%A_ThisMenuItem%, %A_AppData%\Roaming\discord
RefreshTray()
FileDelete, %A_LocalAppData%\Programs\Discord account switcher\Active account.txt
FileAppend, %A_ThisMenuItem%, %A_LocalAppData%\Programs\Discord account switcher\Active account.txt
Run, %A_AppData%\Microsoft\Windows\Start Menu\Programs\Discord Inc\Discord.lnk
return
It seems to only rename the folders, the contents of the folders doesn't move.
User avatar
mikeyww
Posts: 26611
Joined: 09 Sep 2014, 18:38

Re: FileMoveDir not moving folder contents  Topic is solved

Post by mikeyww » 18 Sep 2021, 10:00

The following one-line script may be revealing.

Code: Select all

MsgBox % A_AppData
If your directory is not moved, then reduce your script to a single line so that you can test just that part. Display the ErrorLevel as well as the specific paths, so that you can verify them. Add lines that use FileExist and then display the results, so that you can understand whether your file paths exist.
SkipperBook3
Posts: 6
Joined: 18 Sep 2021, 09:18

Re: FileMoveDir not moving folder contents

Post by SkipperBook3 » 18 Sep 2021, 10:07

mikeyww wrote:
18 Sep 2021, 10:00
The following one-line script may be revealing.

Code: Select all

MsgBox % A_AppData
If your directory is not moved, then reduce your script to a single line so that you can test just that part. Display the ErrorLevel as well as the specific paths, so that you can verify them. Add lines that use FileExist and then display the results, so that you can understand whether your file paths exist.
Ah, mistyped directory. Thanks for spotting this for me! It's always these little details I completely miss, even after staring at them for so long. I figured the commands were written correctly because I wasn't getting an ErrorLevel.
User avatar
mikeyww
Posts: 26611
Joined: 09 Sep 2014, 18:38

Re: FileMoveDir not moving folder contents

Post by mikeyww » 18 Sep 2021, 10:26

You would have no way to assess ErrorLevel, because your script neither checks nor reveals the ErrorLevel. :)
SkipperBook3
Posts: 6
Joined: 18 Sep 2021, 09:18

Re: FileMoveDir not moving folder contents

Post by SkipperBook3 » 20 Sep 2021, 10:19

mikeyww wrote:
18 Sep 2021, 10:26
You would have no way to assess ErrorLevel, because your script neither checks nor reveals the ErrorLevel. :)
I did include an if ErrorLevel SoundBeep however I removed it in my example script. Either way I should've been more diligent in checking the directories.
Post Reply

Return to “Ask for Help (v1)”