app that saves output files as they are generated.

Don OHara
Don OHara used Ask the Experts™
on
I now use an app that generates a 'work' file each time its run. The work file is always generated with the same treename.  Now I run a new program that will process a set of the 'work' files... But only if I remember to save&rename each 'work' file before running the app.

So I am interested in a new program that runs continuously on Windows( 7&10) that checks for a new version of the work file (pauses/sleeps for 30 seconds, then checks ) .  If this program finds a new work file, the program copies the file to a particular directory, and removes the work file from the app's directory.

I would have this program start up when Windows is started.  This program would retrieve its parameters (treename of target work file and the save directory) from a 'INI' type file. The name of the INI file would be a command line argument or queried to the user.. All INI files are stored on one base directory This allows me to have 2 or more instances running at the same time.

Are there scripting languages that run on Windows?  If not, my computers do currently have Python running.

Thanks,
Don OHara
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Hi Don,

> Are there scripting languages that run on Windows?

Yes...many! You've already mentioned Python. Others are AutoHotkey (my personal favorite), AutoIt (AutoHotkey is a fork of AutoIt), Windows batch files (.bat), Perl, PowerShell, REXX (my fav until I discovered AutoHotkey), Ruby, VBScript, and plenty more. Regards, Joe

Author

Commented:
Which can be used natively on Windows - without any installation issues? And would do what I want?

Thanks Joe.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Hi Don,

> Which can be used natively on Windows

Of the ones that I listed, Windows batch files, PowerShell, and VBScript are included natively with Windows.

> without any installation issues

Well, even though PowerShell is installed with Windows, I've seen it cause grief for some users due to the ExecutionPolicy issue. A Google search on that will get you all you need to know about it, and here's an interesting article that discusses it:
How to create and run a PowerShell script file on Windows 10

> And would do what I want?

I'm sure that PowerShell and VBScript can do it (and maybe batch files in the hands of the right expert, such as Bill Prew). But I'm not an expert in any of them, so best to wait for other folks to jump in. I could do it in AutoHotkey, but that's not built into Windows. However, one advantage of AutoHotkey is that it has a compiler that can produce a stand-alone EXE file that can run on any system without AutoHotkey being installed. To be clear, it's not a "compiler" in the traditional sense...it does not generate object code for your script...rather, it packages the AutoHotkey interpreter and your script's source code into the EXE file. That said, it works a charm! Regards, Joe

Author

Commented:
Hi Joe,
Your comments are very interesting.
Sounds like AutoHotkey is versatile (once it is learned). I am looking at the Website now- most likely will download it.
Being an EXE file, I should be able to run multiple instances (using different INI files to track different files). As long as I can choose the sleep time, this should not hinder computer performance.

Thoughts?

Thanks, Joe

Author

Commented:
I am reading the user guide now.
Is it possible to send me an AutoHotkey script that does this task.

Thanks, Don
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
> Sounds like AutoHotkey is versatile

Yes, AutoHotkey is a very robust language, including native support for COM (Component Object Model) calls.

> Being an EXE file, I should be able to run multiple instances (using different INI files to track different files).

Yes, but be sure to set #SingleInstance to Off, documented here:
https://www.autohotkey.com/docs/commands/_SingleInstance.htm

> As long as I can choose the sleep time

No problem...Sleep doc here:
https://www.autohotkey.com/docs/commands/Sleep.htm

> Is it possible to send me an AutoHotkey script that does this task.

Sure, it's possible...everything in your initial post is doable with AutoHotkey, although I don't yet know how long it would take to write (and test on both W7 and W10). Is this a project for work where you have a budget for developing the program or are you looking to have it developed pro bono?

I'm leaving my office now for a few hours. Will check back into the thread as soon as I return. Regards, Joe

Author

Commented:
Hi Joe,
Thanks for responding.
I am doing this for myself. I am the one who occasionally forgets to save a file so the my second level review is missing files.

I prefer to write this myself to learn Autohotkey. I always like to learn new tools.
My request to you was for a simple sample for me to use to learn.
One that would not take long to put together. even if only on W-7.

Thanks, Don
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Hi Don,
Sorry I didn't get back to this today. It's on the to-do list for tomorrow. Regards, Joe
Developer
Fellow 2017
Most Valuable Expert 2018
Commented:
> I prefer to write this myself to learn Autohotkey. I always like to learn new tools.

Excellent! Very glad to hear that.

I pulled together this list of articles and videos that I published here at Experts Exchange that have AutoHotkey code in them that should help as you learn the language (start with the AutoHotkey - Getting Started article):

Articles
Test IP Addresses with PING
Answer Skype Calls with Bluetooth Headset
AutoHotkey - Getting Started
How to copy the short link of an ID at Experts Exchange to the clipboard with a single keystroke
How to solve the problem of incorrect System Uptime being reported when a system has been up for a long time (approximately 50 days or more)
How to create an on/off toggle to mute the system audio/sound with a single mouse click or single keystroke
How to download number of Views, Endorsements, Points for Experts Exchange Articles and Videos
How to move all windows on one monitor to another monitor with a single keystroke
AutoHotkey Switch-Case

5-minute video Micro Tutorials
On-Screen Display for CapsLock State (On or Off)
On-Screen Display for CapsLock State (On or Off) - Enhanced
Check for and download updated file - Example - FileZilla
How to download number of Views, Endorsements, Points for Experts Exchange Articles and Videos--Demo
ArticlesVideosEE: Download statistics on Experts Exchange Articles and Videos - Demo of Enhancements

> My request to you was for a simple sample for me to use to learn. One that would not take long to put together.

I hope the articles and videos above help you to learn. Writing a quick-and-dirty script with no error checking (hoping that nothing fails) and modest testing would probably take an hour or two. It would likely take several hours to write a robust script with best-practices error-checking, such as testing for a failed FileCopy, failed IniRead, param missing on command line, INI file specified on command line not existing, etc. Also, since you say "or queried to the user", you would need to have a GUI as well as the CLI.

Here are some code snippets for the features you mention:

> checks for a new version of the work file

FileExist(FilePattern)

Open in new window

Doc here:
https://www.autohotkey.com/docs/commands/FileExist.htm

> pauses/sleeps for 30 seconds

Sleep,30000

Open in new window

Doc here:
https://www.autohotkey.com/docs/commands/Sleep.htm

> copies the file to a particular directory

FileCopy,SourcePattern,DestPattern[,Overwrite]

Open in new window

Doc here:
https://www.autohotkey.com/docs/commands/FileCopy.htm

> removes the work file from the app's directory.

To delete permanently:

FileDelete,FilePattern

Open in new window

To send to recycle bin:

FileRecycle,FilePattern

Open in new window

Doc here:
https://www.autohotkey.com/docs/commands/FileDelete.htm
https://www.autohotkey.com/docs/commands/FileRecycle.htm

> program start up when Windows is started

Create a shortcut to the file with this:

FileCreateShortcut,Target,LinkFile[,WorkingDir,Args,Description,IconFile,ShortcutKey,IconNumber,RunState]

Open in new window

Then add it to the Startup folder via FileCopy and the built-in variable A_Startup (full path and name of Startup folder in current user's Start Menu). Doc here:
https://www.autohotkey.com/docs/commands/FileCreateShortcut.htm
https://www.autohotkey.com/docs/Variables.htm#Startup

> retrieve its parameters (treename of target work file and the save directory) from a 'INI' type file

Read the INI file with this:

IniRead,OutputVar,Filename,Section,Key[,Default]

Open in new window

If you ever need to write or delete INI keys, use IniWrite and IniDelete. Doc here:
https://www.autohotkey.com/docs/commands/IniRead.htm
https://www.autohotkey.com/docs/commands/IniWrite.htm
https://www.autohotkey.com/docs/commands/IniDelete.htm

> name of the INI file would be a command line argument

Here's a subroutine that I use in many of my programs to get the command line arguments into easy-to-use, non-array variables (Param1, Param2, etc.):

GetParams:
NumParams:=A_Args.Length()
Loop,%NumParams%
  Param%A_Index%:=A_Args[A_Index]
Return

Open in new window

You may, of course, refer to them with array syntax, such as A_Args[1].

> or queried to the user

Use FileSelectFile, doc here:
https://www.autohotkey.com/docs/commands/FileSelectFile.htm

And, when you need it, FileSelectFolder, doc here:
https://www.autohotkey.com/docs/commands/FileSelectFolder.htm

Speaking of best-practices error checking, I suggest that you study two features. First, the built-in ErrorLevel variable. Many commands set this to indicate success or failure, and since some commands set it to values higher than 1, check the doc carefully on each command so you know what to check for, such as FileCopy, where it is set to the number of files that could not be copied due to an error. Doc here:
https://www.autohotkey.com/docs/misc/ErrorLevel.htm

Second, Try-Catch pairs. You're probably familiar with this concept from other languages. They allow you to run some code if an exception is raised during execution of a statement. Doc here:
https://www.autohotkey.com/docs/commands/Try.htm
https://www.autohotkey.com/docs/commands/Catch.htm

Regards, Joe

Author

Commented:
Thanks Joe.
I will work at this right after Thansksgiving.

You have a great holiday.

Don
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
You're welcome, Don. You have a great one, too...and safe travels, if you're travelling. I'll be with family for the holiday and likely won't be on Experts Exchange until Monday, but I'll check back into the thread then to see how you're doing. Regards, Joe
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Hi Don,

I'm back from my Thanksgiving holiday with family...had a great time...hope your Thanksgiving was good, too.

Do you need further help on this question? Regards, Joe

Author

Commented:
Hi Joe,
I apologize for not being around to reply.
Just got back myself from an extended trip.
I will follow up very soon.
Don
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
Welcome back! I hope your trip was a good one. I'll be here during the next several days to help if you need it. Regards, Joe

Author

Commented:
The key to my question was for me to learn about the best robust scripting language for my particular situation, and Joe is an 'expert' in that. I have developed scripts and will continue to do more.

Thanks, joe
Will stay in touch.
Joe WinogradDeveloper
Fellow 2017
Most Valuable Expert 2018

Commented:
You're welcome, Don, and thanks to you for writing the very nice Testimonial...much appreciated!

I also appreciate that you selected one of my posts as the ASKER CERTIFIED SOLUTION, but I'd like to make a suggestion on that. The post where I said "Welcome back! I hope your trip was a good one..." is not really the "solution". The post with the article/video references and the sample code snippets is the "solution"...this post: #a42986725

I think it would be far better for this thread to make that post the "solution". Regards, Joe

Update: Thanks for making the change!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial