Need to move files from removable drive to pc location Topic is solved
Need to move files from removable drive to pc location
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.
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.
Re: Need to move files from removable drive to pc location
Hello,
AutoHotkey has documentation that can help you understand how the functions work. It also includes examples. Below is a start.
FileMove • FileRecycle
Both of these functions will accept a file pattern.
AutoHotkey has documentation that can help you understand how the functions work. It also includes examples. Below is a start.
FileMove • FileRecycle
Both of these functions will accept a file pattern.
Re: Need to move files from removable drive to pc location
That would be quite simple then. I have tested it out and literally nothing happens.
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?
Code: Select all
if FileExist("D:\GoPro\*.txt")
MsgBox "At least one .txt file exists."
FileMove "D:\GoPro\*.txt", "D:\"
FileDelete "D:\GoPro\*.txt"
However, it doesn't move the file, and it doesn't delete the file.
Surely it would be as simple as that code right?
Re: Need to move files from removable drive to pc location
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)
(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)
Re: Need to move files from removable drive to pc location
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.gregster wrote: ↑03 Apr 2023, 04:12Please 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)
It's quite late now, I'll look into the error handling tomorrow, but I hate error handling it's always SO complicated...
Re: Need to move files from removable drive to pc location
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.
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.
Re: Need to move files from removable drive to pc location
Great that it works now.Seabottom wrote: ↑03 Apr 2023, 04:47Thanks, 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.
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!
Re: Need to move files from removable drive to pc location
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?
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\*.*"
Re: Need to move files from removable drive to pc location
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?
See DirSelect.
Re: Need to move files from removable drive to pc location
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.boiler wrote: ↑04 Apr 2023, 03:36Your 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?
See DirSelect.
I'm getting this error now. And also, a file is created in the script location named "Output", no extension.
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.
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.
Re: Need to move files from removable drive to pc location
The following worked here. Use full paths.
If Output is your variable name, then do not quote it, because that would indicate a literal string.
Code: Select all
#Requires AutoHotkey v2.0
source := 'D:\images\arrows\*.png'
dest := 'I:\test'
DirCreate dest
FileMove source, dest
MsgBox 'Done!', 'Status', 64
Re: Need to move files from removable drive to pc location
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.
Re: Need to move files from removable drive to pc location
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\*.*
Re: Need to move files from removable drive to pc location
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
Re: Need to move files from removable drive to pc location
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?
Re: Need to move files from removable drive to pc location
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:
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
Re: Need to move files from removable drive to pc location
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!boiler wrote: ↑10 Apr 2023, 04:53Yeah, 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 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
Re: Need to move files from removable drive to pc location Topic is solved
clearly its trying to run the script as though it were an ahkv1 script
put #Requires AutoHotkey v2.0 to dispel any ambiguity
put #Requires AutoHotkey v2.0 to dispel any ambiguity