Using Lua How to read or write in different directory? - file

I am able to create write read and append in same directory using Lua. Now I want to write to a sub directory. Can someone please show? Thx.
I.e. Existing Current dir: C:\main
Existing subdirectory: C:\main\sub
New file: C:\main\sub\newfile.txt

Writing into a sub-directory is no different from writing into a file in the same directory. The only issue you may run into is with escaping Windows path separators, so instead of "C:\main", use [[C:\main]] or "C:\\main".
If the folder needs to be created, you'll need to use shell commands or lfs library as the default Lua interpreter doesn't provide API to create folders.

Related

Do you need to be specific about a file location when using os or do you still ned to write (folder/file)?

Let's say I have a file called hello.txt in the folder called coding, and I want to open that in python. I know that if I don't use os, I would have to write open("coding/hello.txt") but if I would write os.open would I still have to specify the folder like ("coding/hello.txt") or can I just write os.open("hello.txt") because I am using os?
"File" and "operating system" can mean a lot of different things, but typically operating systems have the concept of a "current" or "working" directory. Each process has its own current directory, and if you don't specify a directory for a file it uses the current directory.
Do not rely on this. Too many things can change the current directory unexpectedly, and your program will suddenly start using a different file.
Instead always specify the full file path like open("/usr/tmp/coding/hello.txt") or whatever is appropriate for your operating system; it will probably provide environment variables or something for the user's home or temporary directories.
Note that your examples "coding/hello.txt" and "hello.txt" both use the current directory, and are different files.

Overwrting multiple file using NSIS Script (how Win Zip extractor does)

I am writing a script using Null Script which install around 6000 files in INSTALLDIR i.e. C:\ABC folder.
I have done this using
File /r "ABC"
in install section.
It is just a simple extractor (no registry entries and no uninstall.exe created during install).
Now, if I run the same exe again then I want my exe to display a message box to the user while overwriting the files containing the options
Yes,
Yes too all, or
exit the installer
i.e. How WinZip software does while extracting the same zip file in the same location multiple times.
If I set the SetOverwrite value to off then during install (2nd time) my EXE just skips the file installation without notifying the user. Also using IFFILEEXIST I can check a single file or *.* files but cannot do one to one mapping.
Please suggest how can I implement this. If this question is already posted then please send me the link.
Thanks in advance.
It is not possible to get this behavior in NSIS when using File /r. You might be able to pull off something similar by generating the file list at compile time by executing a batch file with !system and then check if each file exists and maybe delete the old one at run-time but you are not going to get the dialog without a custom plugin. NSIS itself only supports basic Abort/Retry/Cancel and Yes/No dialogs.
If you only want to use free tools, why not just use 7-Zip to create a self extracting archive?

I want to create .exe file to create multiple folder at a same time

I want to create .exe setup or batch file to create Multiple folders at same time.
and folder name prompt to give or take from .txt file.
If you are ok to enter the name of the folder each time, you can simply use the md command of the Windows Command Line!
Syntax: md MyFolderName
Your question is Operating system dependent.
To create an executable
In windows you can use Visual Studio console application to create a c++ code and build it to obtain a .exe file. You have to take care on the linking options.
To create a directory simply do mkdir("foldername") and to read or write from txt file, create a file stream and use getline to read the names of folder.
In linux I suppose it can be done by writing a bash script.

How do I keep WZZIP from creating a zip that makes a folder when unzipped?

I'm looking at an automated process (utilizing a "DOS" .BAT file) that creates zip files with a simple command like...
wzzip [path][zip file name] [files to be zipped]
...but when a partner receives and unzips these files, it's creating a folder with the name of the zip file and putting the files inside it, and they need (well, or at least prefer) it to just extract the files to the "." folder.
Is there a way to get wzzip to use "." instead of creating an eponymous folder? The only thing I could see in the options list was to maybe hack something out of -r-p (even though I DON'T actually want it to recurse folders when zipping), but I was hoping there might be a better way.
The partner company is apparently running Linux, so while I see that wzunzip has an option to set the output folder that MIGHT override the default behavior, I'm not sure what the app they are using might allow.
Go to http://www.winzip.com/ and download the Winzip Command Line utilities. Install and use WZZIP.EXE.

Call .bat file from anywhere in the directory using python

I need to call a .bat file from anywhere in the directory without including the specific directory in the script. You'll just need to specify the name of .bat file you want to call and then run. Is this possible?
Add the .bat file's directory into your PATH.
This is an article for you.
http://www.computerhope.com/issues/ch000549.htm
do you mean calling a script without specifying the exact location from commandline?
there are two ways:
add it to your path (eg: set it in your PATH environment variable)
setup an alias/some sort of shortcut in your bashrc/whatever CLI you are using (since you are using windows, one example would be to setup a cmdlet in windows powershell or something)

Resources