Need to move files from removable drive to pc location Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
Seabottom
Posts: 25
Joined: 30 Nov 2013, 18:59

Need to move files from removable drive to pc location

Post by Seabottom » 02 Apr 2023, 04:05

I was thinking for easy use, just put the .ahk file on the thumbdrive, so there's no issues with drive letters changing.
I'd like the script to move GoPro .mp4 and .jpg files to a fixed hardcoded location on my pc. And then delete everything in that folder where it came from.
Sounds pretty simple, but I'm not sure where to even start. Which commands should I be using. Need some pointers please, or a draft solution.

User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Need to move files from removable drive to pc location

Post by mikeyww » 02 Apr 2023, 04:51

Hello,

AutoHotkey has documentation that can help you understand how the functions work. It also includes examples. Below is a start.

FileMoveFileRecycle

Both of these functions will accept a file pattern.

User avatar
Seabottom
Posts: 25
Joined: 30 Nov 2013, 18:59

Re: Need to move files from removable drive to pc location

Post by Seabottom » 03 Apr 2023, 00:43

That would be quite simple then. I have tested it out and literally nothing happens.

Code: Select all

if FileExist("D:\GoPro\*.txt")
    MsgBox "At least one .txt file exists."
FileMove "D:\GoPro\*.txt", "D:\"
FileDelete "D:\GoPro\*.txt"
When I run the .ahk, I get the messagebox showing, so I know that AHK can see the test.txt file.
However, it doesn't move the file, and it doesn't delete the file.

Surely it would be as simple as that code right?

gregster
Posts: 9014
Joined: 30 Sep 2013, 06:48

Re: Need to move files from removable drive to pc location

Post by gregster » 03 Apr 2023, 04:12

Please don't copypaste ChatGPT-created code into these forums - it's against the forum rules (and often the code has faulty logic or invented syntax). Thank you!
(I removed your last post.)

You are currently posting in the AHK v2 help section - my guess is that you are actually using AHK v1.
This could also explain why your code above doesn't work. In v1, it would surely fail.
So... which version is this request for?

Generally, you should look into the error handling of Filemove, to find out why it doesn't work (after you decided which AHK version to use):
https://www.autohotkey.com/docs/v1/lib/FileMove.htm#Error_Handling (AHK v1)
https://www.autohotkey.com/docs/v2/lib/FileMove.htm#Error_Handling (AHK v2)

User avatar
Seabottom
Posts: 25
Joined: 30 Nov 2013, 18:59

Re: Need to move files from removable drive to pc location

Post by Seabottom » 03 Apr 2023, 04:42

gregster wrote:
03 Apr 2023, 04:12
Please don't copypaste ChatGPT-created code into these forums - it's against the forum rules (and often the code has faulty logic or invented syntax).

You are currently posting in the AHK v2 help section - my guess is that you are actually using AHK v1.
This could also explain why your code above doesn't work. In v1, it would surely fail.
So... which version is this request for?

Generally, you should look into the error handling of Filemove, to find out why it doesn't work (after you decided which AHK version to use):
https://www.autohotkey.com/docs/v1/lib/FileMove.htm#Error_Handling (AHK v1)
Oh I'm so sorry, I didn't know there was a new version. AHK has never had a new version before. Also, I just googled "filemove" and was taken to this forum and made a post. Again, I didn't think to check for a new version, so this would be for version 1, but really, who cares? I installed the new version and it has auto detect that seems to work great anyway.
It's quite late now, I'll look into the error handling tomorrow, but I hate error handling it's always SO complicated...

User avatar
Seabottom
Posts: 25
Joined: 30 Nov 2013, 18:59

Re: Need to move files from removable drive to pc location

Post by Seabottom » 03 Apr 2023, 04:47

Thanks, after installing the V2, the above code that I posted works flawlessly. Mikeyww couldn't have known I was looking for V1 code when I posted in the V2 forum.
I bet you'll have a lot of managing people/posts like mine for the next year if not two, due to such a sudden change.

gregster
Posts: 9014
Joined: 30 Sep 2013, 06:48

Re: Need to move files from removable drive to pc location

Post by gregster » 03 Apr 2023, 05:10

Seabottom wrote:
03 Apr 2023, 04:47
Thanks, after installing the V2, the above code that I posted works flawlessly. Mikeyww couldn't have known I was looking for V1 code when I posted in the V2 forum.
I bet you'll have a lot of managing people/posts like mine for the next year if not two, due to such a sudden change.
Great that it works now.
The development of v2 actually took a long time, so yes, especially occasional forum visitors are surprised that is the main release now. Although a lot of the syntax changed, and v2 is not very backwards compatible, both versions can be used along with each other - you can also tell the AHK launcher which version to use, if auto-detect doesn't work or the code is ambiguous (see #Requires). Anyway, for v1, we still have separate support forums available.
Happy coding!

User avatar
Seabottom
Posts: 25
Joined: 30 Nov 2013, 18:59

Re: Need to move files from removable drive to pc location

Post by Seabottom » 04 Apr 2023, 02:02

Hi, I got the code working somewhat now, and I tested it on the desktop, with a dummy folder and files - works flawlessly.
Then I put the script onto my GoPro SD card with an older laptop card reader (as GoPro must be read-only or something), and now the script doesn't work. I can move files off of the GoPro manually no problem though.
I'm thinking now that AHK needs to write something in order to work, and maybe that's why the script only works outside the SD card environment???

Also, I don't particularly like hard coding the end destination.
I have googled a fair bit and no results - How do I get the explorer prompt to select a location of where to dump my files?

Code: Select all

FileMove "100GOPRO\*.MP4", "D:\GoPro\"
FileMove "100GOPRO\*.JPG", "D:\GoPro\"
FileDelete "100GOPRO\*.*"

User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: Need to move files from removable drive to pc location

Post by boiler » 04 Apr 2023, 03:36

Seabottom wrote: Then I put the script onto my GoPro SD card with an older laptop card reader (as GoPro must be read-only or something), and now the script doesn't work. I can move files off of the GoPro manually no problem though.
Your source path is having it just look for files in a folder named 100GOPRO inside the working directory, which by default is the script’s directory. Isn’t there some drive designation that gets assigned when you insert your SD card? What does File Explorer show when you display the SD card’s files?

Seabottom wrote: How do I get the explorer prompt to select a location of where to dump my files?
See DirSelect.

User avatar
Seabottom
Posts: 25
Joined: 30 Nov 2013, 18:59

Re: Need to move files from removable drive to pc location

Post by Seabottom » 04 Apr 2023, 04:18

boiler wrote:
04 Apr 2023, 03:36
Seabottom wrote: Then I put the script onto my GoPro SD card with an older laptop card reader (as GoPro must be read-only or something), and now the script doesn't work. I can move files off of the GoPro manually no problem though.
Your source path is having it just look for files in a folder named 100GOPRO inside the working directory, which by default is the script’s directory. Isn’t there some drive designation that gets assigned when you insert your SD card? What does File Explorer show when you display the SD card’s files?

Seabottom wrote: How do I get the explorer prompt to select a location of where to dump my files?
See DirSelect.
Thanks, that's exactly what I needed, but now I'm having other issues. I'm grasping at straws here or whatever it's called, I'm stumped. Can I just get a working code please? The examples in the docs are terrible.
I'm getting this error now. And also, a file is created in the script location named "Output", no extension.

Image

The first line is executed and the .MP4 is moved out of the folder, but not into the target folder (so lost forever).
This is my current test environment on the desktop.

Image

I'm really not asking for much here, it's so simple, just move the files out of the folder, into a designated folder, and delete everything else in the source folder. It shouldn't be this hard.

User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Need to move files from removable drive to pc location

Post by mikeyww » 04 Apr 2023, 05:59

The following worked here. Use full paths.

Code: Select all

#Requires AutoHotkey v2.0
source := 'D:\images\arrows\*.png'
dest   := 'I:\test'
DirCreate dest
FileMove source, dest
MsgBox 'Done!', 'Status', 64
If Output is your variable name, then do not quote it, because that would indicate a literal string.

User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: Need to move files from removable drive to pc location

Post by boiler » 04 Apr 2023, 06:37

Seabottom wrote:
04 Apr 2023, 04:18
I'm really not asking for much here, it's so simple, just move the files out of the folder, into a designated folder, and delete everything else in the source folder. It shouldn't be this hard.
Yeah, it’s not hard. The AHK part is the easy part. You SD card is not really a folder on your desktop named 100GOPRO. That may be the folder that’s on the removable disk, and you need to identify the actual path to that folder including the drive letter, as mikeyww’s code indicates.

User avatar
Seabottom
Posts: 25
Joined: 30 Nov 2013, 18:59

Re: Need to move files from removable drive to pc location

Post by Seabottom » 10 Apr 2023, 04:20

Hi, sorry, I thought I was done, but how do I make this work?

Code: Select all

Input := DirSelect(, 0, "Where is the footage located?")
Output := DirSelect(, 3, "Select where to put the footage")
FileMove Input\*.MP4, Output
FileMove Input\*.JPG, Output
MsgBox "All files moved to selected location"
FileDelete Input\*.*

User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: Need to move files from removable drive to pc location

Post by boiler » 10 Apr 2023, 04:39

Code: Select all

Input := DirSelect(, 0, "Where is the footage located?")
Output := DirSelect(, 3, "Select where to put the footage")
FileMove Input "\*.MP4", Output
FileMove Input "\*.JPG", Output
MsgBox "All files moved to selected location"
; FileDelete Input "\*.*" ; be careful with this line!

Explained: Expressions

User avatar
Seabottom
Posts: 25
Joined: 30 Nov 2013, 18:59

Re: Need to move files from removable drive to pc location

Post by Seabottom » 10 Apr 2023, 04:47

Oh my god, that's pretty much what I already did! All I needed was a space between input and quote sign?? I really looked for this kind of information in the wiki, I don't suppose we could add another example?

User avatar
boiler
Posts: 16957
Joined: 21 Dec 2014, 02:44

Re: Need to move files from removable drive to pc location

Post by boiler » 10 Apr 2023, 04:53

Yeah, that’s all that’s needed, but it’s really not at all what you already did, unless you had quotes in a version you didn’t show us. Without the quotation marks, there is nothing to distinguish between a literal string and what’s in a variable.

The space is the shortcut for the concatenation operator, which is a dot with a space on both sides, like this:

Code: Select all

FileMove Input . "\*.MP4", Output

User avatar
Seabottom
Posts: 25
Joined: 30 Nov 2013, 18:59

Re: Need to move files from removable drive to pc location

Post by Seabottom » 11 Apr 2023, 02:40

boiler wrote:
10 Apr 2023, 04:53
Yeah, that’s all that’s needed, but it’s really not at all what you already did, unless you had quotes in a version you didn’t show us. Without the quotation marks, there is nothing to distinguish between a literal string and what’s in a variable.

The space is the shortcut for the concatenation operator, which is a dot with a space on both sides, like this:

Code: Select all

FileMove Input . "\*.MP4", Output
I see. Yes, I did try to put it in quotes first, but it didn't like that so I removed them and still nothing so... But then I just need to put a space between. Good to know!
I try to run the program now and I get an error message about call to a non-existent function. It didn't ask me if it was V1 or V2 before running
Image

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Need to move files from removable drive to pc location  Topic is solved

Post by swagfag » 11 Apr 2023, 03:28

clearly its trying to run the script as though it were an ahkv1 script
put #Requires AutoHotkey v2.0 to dispel any ambiguity

Post Reply

Return to “Ask for Help (v2)”