Autoit All Files In Dir

.OverviewThis post shows how to quickly get the current script directory using PowerShell, VBScript and Batch – the most commonly used scripting languages for Windows.The scripts I write usually read in other files or call other scripts. In order for these scripts to run from any location – such as a UNC path – without hard coding paths they need to use relative paths.
I have a folder containing many subfolders. Inside them many different files. I want to copy all.doc and.docx files using autoit into a new folder. The AutoIt FileDelete function is used to delete files. If a directory path is supplied, all files within the given directory will be deleted, leaving behind a empty folder – this behavior is different than that of FileRecycle, wheres the folder will be moved as well as its contents.
Depending on how the script is called the working directory may not be the same as the script file. For example, if your current directory is C:Windows and you run the script serversharesomepathmyscript.cmd then any relative paths in the script file won’t work correctly.One way around this is to make the script change working directory right at the start and then use relative paths after that. Sagera 2.0 download for mac. But in some situations – such as batch files on UNC paths – this won’t aways work. The best way to get around this is to determine the directory that the script resides in at the start of the script and then make all other paths reference that.Because I jump around various scripting languages all the time, I tend to forget the best way to do this and have to hunt for examples in old scripts.
As a reference for myself this post gives the template for getting the current script directory in the languages I tend to use: PowerShell, VBScript and batch. Windows BatchWindows batch is the trickiest in some ways – it also is the one that cannot support UNC working directories. There is a built-in variable%dp0 which expands to the path that the script is located in including the trailing slash. This can make for messy looking scripts because to run setup.exe from the current script directory you would use%dp0setup.exe.

This works great but can be a little confusing for others to read because it looks like a typo.My preferred method is to create a new variable at the top of the script using%dp0 and then stripping the trailing backslash. Here is the script.