How to reffer to a file in %appdata%\Folder in Autoit? - scripting

I need to reffer to a file in Autoit, let's call it's location %appdata%\folder\file.txt
How can I call to it in Autoit? I've seen %appdata% reffered as #AppDataCommonDir in it, but I can't get the full path right.
Thanks.

You mean the following?
$file = #AppDataCommonDir & "\folder\file.txt"

include
Local $filePath
$filePath = _PathFull("Folder\File.txt", #AppDataDir)
MsgBox (0, "Path", $filePath)

Related

When to use $path, $dir or $file as a variable name

Obviously I know the difference between a file and a directory :)
I also know that both a file and a directory have a path.
But when writing code, what will you use when?
E.g.:
I want to clear all *.js files in a directory...
$filesystem->removeJsFiles($jsDir|$jsPath);
Copy an XML file...
$filesystem->copy($xmlFile|$xmlPath);
So when will you typically use $path as a variable instead of $dir or $file (or the other way around)?
If you don't need to distinguish between filenames, paths and file handles I would use simply jsDir and xmlFile. Otherwise I would use jsDirName or jsDirPath and xmlFileName or xmlFilePath, and jsDir and xmlFile for file handles.

How to write to gzip file from elixir code

I would like to write gzip file from elixir code.
I tried to following code, but it doesn't work well.
io_device = File.open!("/path/to/file.gzip", [:write, :compressed])
IO.write(io_device, "test")
IO.write returns :ok, but, /path/to/file.gzip is empty.
How can I write to gzip file?
You can also do whole thing in one step:
File.write "/path/to/file.gzip", "test", [:compressed]
You need one more step: close the file so that any buffered data gets written:
File.close io_device

How to read a Bunch of files in a directory in lua

I have a path (as a string) to a directory. In that directory, are a bunch of text files. I want to go to that directory open it, and go to each text file and read the data.
I've tried
f = io.open(path)
f:read("*a")
I get the error "nil Is a directory"
I've tried:
f = io.popen(path)
I get the error: "Permission denied"
Is it just me, but it seems to be a lot harder than it should be to do basic file io in lua?
A directory isn't a file. You can't just open it.
And yes, lua itself has (intentionally) limited functionality.
You can use luafilesystem or luaposix and similar modules to get more features in this area.
You can also use the following script to list the names of the files in a given directory (assuming Unix/Posix):
dirname = '.'
f = io.popen('ls ' .. dirname)
for name in f:lines() do print(name) end

How can I use source script with variables in CygWin?

I'm trying to use external script with variables, but in result I get only "no such file or directory".
1st.ksh
#!bin/ksh
PATHNAME = `dirname $0`
. $PATHNAME/2nd.ksh
Echo $EXTVAR
2nd.ksh
#!bin/ksh
EXTVAR=1
I tried to use "Source" instead of "." (Source $PATHNAME/2nd.ksh) and I get the same result.
To run script I'm using full path to the script - cygdrive/e/Folder/1st.ksh.
2nd.ksh in this path too (cygdrive/e/Folder/).
All rights was granted for both files (chmod u=rwx,g=rwx,o=rwx filename).
If I put files in cygwin home path (/home/username/) I have the same.
Please help to understand what I'm doing wrong.
Thanks in advance!
$() should be used in ksh instead of `` (link)
. should be user instead of source (link)
"=" must not be surrounded with spaces. You should write: PATHNAME=$(dirname $0)
you should be aware of case-sensitiveness: echo, source

Why is this PowerShell script constructing unexpected file paths?

Using tips gleaned from this, this, and this, I've finally been able to get a series of file backup scripts going. However, there's one little thing that I've been unable to solve. No runtime errors, but when I run this script,
$originalPath = "\\Server\Path\_testData\"
$backupPath = "\\Server\Path\_backup\"
#
function supportBackup
{
"$($originalPath) copying DOC XLS PPT JPG GIF PDF WAV AVI to $($backupPath)"
Get-ChildItem $originalPath\* -Include *.doc*, *.xls*, *.ppt*, *.jpg, *.gif, *.pdf, *.wav, *.avi | `
foreach {
$targetFile = $backupPath + $_.FullName.SubString($originalPath.Length);
New-Item -ItemType File -Path $targetFile -Force;
Copy-Item $_.FullName -destination $targetFile
}
"Support File Backup Completed"
}
supportBackup
The original file path gets dumped into the destination directory instead of just the files.
What I want:
\\Server\Path\_backup\files-from-testData-directory
What I get:
\\Server\Path\_backup\_testData\files-from-testData-directory
I know the problem is closely related (if not identical) to this question, but after studying it and trying to apply some of the wisdom from there, using various iterations of the $_.Name variables, I realize I don't have as good an understanding as I thought I did. I need someone to explain to me HOW the destination path and filename are being constructed with the given variables, and what alternate variables (or code) I need to use to achieve my desired results. There's something that's not clicking for me and I need help understanding it.
You're trying too hard. This should suffice:
$originalPath = '\\Server\Path\_testData'
$backupPath = '\\Server\Path\_backup'
$extensions = *.doc*,*.xls*,*.ppt*,*.jpg,*.gif,*.pdf,*.wav,*.avi
function supportBackup {
"$($originalPath) copying DOC XLS PPT JPG GIF PDF WAV AVI to $($backupPath)"
Get-ChildItem "$originalPath\*" -Include $extensions |
Copy-Item -Destination "$backupPath\" -Force
"Support File Backup Completed"
}
supportBackup
You can pipe the results of Get-ChildItem directly into Copy-File. The destination path must end with a backslash, though, otherwise the instruction would try to replace the folder $backupPath with a file of the same name, thus causing an error.