FileCopy Line Doesn't Work

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Bacon19331
Posts: 50
Joined: 09 Apr 2019, 20:45

FileCopy Line Doesn't Work

08 Apr 2020, 19:31

Hello, I made a post last night but I got frustrated and went to bed, I tried to change the variables up so it made more sense to the reader.. Basically I don't know why this file isn't copying to the remote location. I'll put in a screenshot of a MsgBox that looks perfect as the source file and the remote location. Please help me understand what I'm doing wrong.

Image

Code: Select all

#SingleInstance force
FormatTime, time, , yyyy-MM-dd
name := time A_ComputerName
logdir = %A_AppData%\Microsoft\Teapot\

f::
FileCopy, "%logdir%%time%.txt", "C:\OM\%name%.txt"
; MsgBox, "%logdir%%time%.txt", "C:\OM\%name%.txt"
return
User avatar
Cuadrix
Posts: 236
Joined: 07 May 2017, 08:26

Re: FileCopy Line Doesn't Work

08 Apr 2020, 19:41

It's not working because the command thinks that the quotes are a part of the path, which they are not.
You don't need quotes in autohotkey commands because everything is already treated as a string:

Code: Select all

FileCopy, %logdir%%time%.txt, C:\OM\%name%.txt
To write the above as an expression you would do it this way:

Code: Select all

FileCopy, % logdir time ".txt", % "C:\OM\" name ".txt"
User avatar
Bacon19331
Posts: 50
Joined: 09 Apr 2019, 20:45

Re: FileCopy Line Doesn't Work

08 Apr 2020, 19:46

Ok, this worked. Thanks! But just wondering if a space was present in the source path, wouldn't you need quotes?
User avatar
Cuadrix
Posts: 236
Joined: 07 May 2017, 08:26

Re: FileCopy Line Doesn't Work

08 Apr 2020, 20:03

Bacon19331 wrote:
08 Apr 2020, 19:46
Ok, this worked. Thanks! But just wondering if a space was present in the source path, wouldn't you need quotes?
You don't need quotes in commands at all, even if you have a space in your string
Quotes are needed around strings if the string is in an expression though e.g. % "C:\Program Files"
User avatar
Bacon19331
Posts: 50
Joined: 09 Apr 2019, 20:45

Re: FileCopy Line Doesn't Work

08 Apr 2020, 20:08

Ok. Thanks for the help!
User avatar
boiler
Posts: 17043
Joined: 21 Dec 2014, 02:44

Re: FileCopy Line Doesn't Work

08 Apr 2020, 20:18

First thing I showed you in the thread yesterday was to remove the quotes. You then kept saying nothing was working and didn’t reply when I suggested that you show your updated code. So that was it.
User avatar
Bacon19331
Posts: 50
Joined: 09 Apr 2019, 20:45

Re: FileCopy Line Doesn't Work

08 Apr 2020, 20:36

Sorry Boiler, it wasn't working for some reason, as I stated I tried to change the name of the variables but I must have screwed it up somehow.
User avatar
boiler
Posts: 17043
Joined: 21 Dec 2014, 02:44

Re: FileCopy Line Doesn't Work

08 Apr 2020, 20:53

No problem. Just was wondering if it was the quotes the whole time. That’s why it’s good to post your updated code even if you can’t see what could be wrong with it. Another set of eyes usually helps. We’ve all been there.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: drlvanb, OrangeCat, serenite and 382 guests