Create DIR and then make it the default save folder?

Get help with using AutoHotkey and its commands and hotkeys
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Google: Christopher Smith
GitHub: chef23

Create DIR and then make it the default save folder?

05 Feb 2018, 23:45

Is this possible?

I have code this code in a program. BUT, if someone uses the Terminal (computer) and saves something to a different folder, my code breaks.

Code: [Select all] [Download] GeSHi © Codebox Plus

FileDelete, C:\Reports\*.* ; Will delete all files in C:\Reports\ -Folder 
FileRemoveDir, C:\Reports ; Will remove the Reports Folder
FileRecycleEmpty, C:\
FileCreateDir, C:\Reports


How can AHK (in the code) select the default save folder before my code executes? I have researched and read its not possible? This seems like it would be super simple to implement with 1-2 lines...ala 'FileCreateDir'

Thank you for any comments.
Chris
BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

Re: Create DIR and then make it the default save folder?

06 Feb 2018, 01:31

SetWorkingDir :?: I'd guess you can trigger the default download directory using its registry setting ...
garry
Posts: 1421
Joined: 22 Dec 2013, 12:50

Re: Create DIR and then make it the default save folder?

06 Feb 2018, 04:42

usually use at beginning : setworkingdir,%a_scriptdir%
( when start an ahk-script via link )
and maybe change later ...
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Google: Christopher Smith
GitHub: chef23

Re: Create DIR and then make it the default save folder?

07 Feb 2018, 00:14

Thanks. Not sure how I missed that one. I was reading the old forums where many said it was not possible to set a save path...

Chef
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Google: Christopher Smith
GitHub: chef23

Re: Create DIR and then make it the default save folder?

23 Feb 2018, 17:01

Can anyone else assist here?

Again, it seems like a no brainier to have a command in AHK that simple lets you set a save path (C:\Reports) as a AHK script is starting.

I have this code the auto runs reports, and it needs to email them. The dir the emailing program looks for these reports is the C:\Reports folder. But, the issue is, when other people use the computer, they may save a file to a different drive / directory / folder and once that is done, Windows automatically tried to use the last save path for any new file being saved so my path of C:\Reports is washed.

Maybe I am looking at this problem incorrectly.

Help :)
Chris
BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

Re: Create DIR and then make it the default save folder?

24 Feb 2018, 08:47

a) What's the name of the email-program?
b) probably that might help: https://www.online-tech-tips.com/window ... indows-10/ (I'd go for the registry-option!)
burque505
Posts: 546
Joined: 22 Jan 2017, 19:37

Re: Create DIR and then make it the default save folder?

24 Feb 2018, 09:20

@chef423, Windows programs drive me nuts in this regard. The script PersistentSaveFolder might be something you can adapt for your own use. I use it dozens of times a day, although I haven't worked out a bug or two, especially with Acrobat. Someday ... :D

My thought (not knowing what email program you use) is that whenever your script calls the email program and requests a save, it sends the directory path to the appropriate control in the save dialog, which very well may be an "ahk_class #32770", probably ClassNN being Edit2 or maybe Edit3 (just use Window Spy).

(If you're creating the directory, I suppose you'd want to check to make sure it doesn't already exist before you use code as above.)

Remember that hitting Alt+d in a save dialog will highlight that folder path. Try having your script first do a 'send, !d', and then send the path (C:\Folders or whatever you use) to that control. I'm probably explaining this poorly - take a look at the code in that script, there's not much to it.

Regards,
burque505
User avatar
jeeswg
Posts: 4983
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Create DIR and then make it the default save folder?

26 Feb 2018, 04:17

Re. dialogs and save folders. You could try NirSoft RegFromApp, which monitors changes to the registry made by a program. Or you could do a before/after registry comparison by using Regshot.
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Google: Christopher Smith
GitHub: chef23

Re: Create DIR and then make it the default save folder?

26 Feb 2018, 11:40

BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

Re: Create DIR and then make it the default save folder?

26 Feb 2018, 11:52

But, the issue is, when other people use the computer, they may save a file to a different drive / directory / folder and once that is done, Windows automatically tried to use the last save path for any new file being saved so my path of C:\Reports is washed.
... but that's only the case if you try to save your report also via the standard 'SaveAs'-dialog box, right??
That gives me the idea that you're triggering any frontend events to save that file? If that's the case, would you mind to provide (that section of) your code?
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Google: Christopher Smith
GitHub: chef23

Re: Create DIR and then make it the default save folder?

26 Feb 2018, 12:03

Here is the code, this may help. AHK runs and opens the POS (Point of Sale, not Piece of..) and then saves 3 reports (hence me needed the default save path IF it changes somehow), then invokes the sendEmail program. So the folder save path is rendered in AHK, sendEmail really doesnt do anything but literally send the files, specified by name, to the intended user.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Google: Christopher Smith
GitHub: chef23

Re: Create DIR and then make it the default save folder?

26 Feb 2018, 12:04

BoBo wrote:
But, the issue is, when other people use the computer, they may save a file to a different drive / directory / folder and once that is done, Windows automatically tried to use the last save path for any new file being saved so my path of C:\Reports is washed.
... but that's only the case if you try to save your report also via the standard 'SaveAs'-dialog box, right??
That gives me the idea that you're triggering any frontend events to save that file? If that's the case, would you mind to provide (that section of) your code?


Code posted. :)
BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

Re: Create DIR and then make it the default save folder?

26 Feb 2018, 13:49

OK, AFAI remember there's a quite simple option to ensure that you won't have to care for the given (probably wrong) path after a SaveAs-Dialog has opened ...
<fanfare>Simply drop your files full target path instead of the filename alone</fanfare>. I've tested it here and it worked fine. So let's get fingers crossed ;)

There are several parts of your script (eg. timestamp/embedding that batch file processing/timings/etc.) which can be improved. The main thing you should have a look at, replace all Send-events with ControlSend if possible.

PS. you can send the timestring concatenated to the filename in one go.

Code: [Select all] [Download] GeSHi © Codebox Plus

CurrentDate := A_Now
CurrentDate += -1, D
FormatTime, TimeString, %CurrentDate%, M-d-yyyy
Send, % "Detailed_Daily_Report_TEST1_" . TimeString
chef423
Posts: 213
Joined: 28 Aug 2016, 12:10
Google: Christopher Smith
GitHub: chef23

Re: Create DIR and then make it the default save folder?

26 Feb 2018, 16:05

BoBo wrote:OK, AFAI remember there's a quite simple option to ensure that you won't have to care for the given (probably wrong) path after a SaveAs-Dialog has opened ...
<fanfare>Simply drop your files full target path instead of the filename alone</fanfare>. I've tested it here and it worked fine. So let's get fingers crossed ;)

There are several parts of your script (eg. timestamp/embedding that batch file processing/timings/etc.) which can be improved. The main thing you should have a look at, replace all Send-events with ControlSend if possible.

PS. you can send the timestring concatenated to the filename in one go.

Code: [Select all] [Download] GeSHi © Codebox Plus

CurrentDate := A_Now
CurrentDate += -1, D
FormatTime, TimeString, %CurrentDate%, M-d-yyyy
Send, % "Detailed_Daily_Report_TEST1_" . TimeString


BoBo, thank you so much for taking the time from your busy day to respond. I would love to clean the code up to make it more reliable and robust. It does choke from time to time. I understand the sample code you passed me, but I didnt understand the first part of your response. 'fanfare' ??

Return to “Ask For Help”

Who is online

Users browsing this forum: Carl, leon263, london1888, newbieforever, RobbieWilkes, swagfag and 74 guests