Problem with filecopy.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Problem with filecopy.

18 Apr 2021, 20:42

I'm trying to use fileselectfile to select an mp3 file, copy the selected file into the folder and also overwrite a file in the folder with the selected file. Here's my code:

Code: Select all

FileCopy, %dir%\%Sound%, %A_scriptdir%\bits

if !fileexist(A_scriptdir "\bits\" Sound)
{
	FileSelectfile, Change, S1, %dir%, Select an mp3 sound for your mover (or cancel to skip sound unchanged), *.mp3

	if !Errorlevel
	{
		msgbox, 4096, OK, %change%, %A_scriptdir%\bits\#moved.mp3, 1	
		;Filedelete, %A_scriptdir%\bits\#moved.mp3,
		Filecopy, %Change%, %A_scriptdir%\bits\#moved.mp3, 1	
		Filecopy, %change%, %A_scriptdir%\bits, 1	
	}
}					
But I can't overwrite #moved.mp3. I even tried deleting it but still end up with the original sound. What am I doing wrong? Is the issue with using %A_scriptdir%? Thanks.
User avatar
boiler
Posts: 17089
Joined: 21 Dec 2014, 02:44

Re: Problem with filecopy.

18 Apr 2021, 21:17

Does the variable Sound happen to contain #moved.mp3. If so, it would never get past your first if statement since you would have copied a file into that directory with that file name on the line right before it.
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Problem with filecopy.

18 Apr 2021, 22:01

Thanks for the reply, it doesn't as I am seeing the msgbox.
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Problem with filecopy.

18 Apr 2021, 22:13

I think the issue might be caused by the fact that I have used Setworkingdir to the directory containing #moved.mp3. This seems to work:

Code: Select all

if !fileexist(A_scriptdir "\bits\" Sound)
{
	FileSelectfile, Change, S1, %dir%, Select an mp3 sound for your mover (or cancel to skip sound unchanged), *.mp3

	if !Errorlevel
	{
		;msgbox, 4096, OK, %change%, %A_scriptdir%\bits\#moved.mp3, 1	
		Filecopy, %change%, %A_scriptdir%\bits, 1
		Filecopy, %Change%, %A_scriptdir%\bits\temp, 1	
		Filemove, temp, #moved.mp3, 1
	}
}					

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww and 153 guests