I'm programming in vb.net and I need to access information from an ini file. There is also some information that I need to insert into the ini file manually so that the program can access it. For example, I need an array Extensions to contain a set of possible file extensions for my program to loop through. How do I manually insert this into an ini file (ie just typing, without using a program)? What is the syntax?
There is no correct syntax for an array, you can place whatever you like as value.
So you could choose whatever syntax you want, for example: Extensions=.ex1,.ex2,.ex3
and in your code you would parse (for this example split) the INI key's value as you need.
The syntax I used was like the following: Extensions={.ex1,.ex2,.ex3}
Also I created an INI library that would enable me to easily manipulate with that value syntax.
For example:
Dim ini As New IniFile()
ini.Load("My Extensions.ini")
Dim extensions As String()
If ini.Sections(0).Keys("Extensions").TryParseValue(extensions) Then
For Each extension In extensions
Console.WriteLine(extension)
Next
End If
Related
I am trying to convert a *.coverage files into XML and then use them and publish code coverage in Jenkins. However, the path to the coverage file always is different and contains Timestamp. Due to that when I call CodeCoverage.exe and I am trying to pass a pattern instead of the direct path and direct file name.
Basically everything works when I point directly to the file, but when the pattern is used, nothing is happening.
*This is working*
C:\CodeCoverage\CoverageTool\CodeCoverage.exe analyze -output:.\TestResults\coverage.xml ".\TestResults\coveragefiles\test.coverage
*This is not working*
C:\CodeCoverage\CoverageTool\CodeCoverage.exe analyze -output:.\TestResults\coverage.xml ".\TestResults\**\*.coverage
Now trying to make it working in cmd, but letter will put it to the groovy (Jenkinsfile) as a bat command.
Is it even possible in that way? Should I first find a string, make a string variable, and pass it to the codecoverage ? thanks in advance
I am new to lua to trying to understand and put pieces to together and looking out for some help.
I have gone through the existing articles on lua file looping but unable to get the desired output.
Question - I have a folder with files, Folder path - "D:\Test_Files\Outbound\Client\final"
Files in the folder with extension - .txt
Trying to :
Get the count of files in the folder(in this case "final" folder).
Read every file, building a loop something similar to this:
list = {}
for i=0,(#Totalfilecount) do
local fr = io.open('D:\Test_Files\Outbound\Client\final\'..filename.,'rb')
local f = fr.read('*.txt')
Customfunction(f) -- Passing file content to customfunction to apply business logic.
end
Questions :
How to get file count from a directory?
How to read the directory to check if the files with "*.txt" exist?
How to use table list to store each file name and read through the loop?
How to read each file via loop and pass the value to function "Customfunction(f)"?
Code is expected to run on windows. Please share suggestions in pure lua without using external file system functions such as 'lfs' as we do not like to import external functions.
Any Suggestions/help will be greatly appreciated!
You can't (at least shouldn't) do this without extensions to Lua. To accomplish this, you have to download LuaFileSystem library. You can do it using LuaRocks:
$ luarocks install luafilesystem
Use library as such:
require "lfs"
function dirtree(dir)
assert(dir and dir ~= "", "Please pass directory parameter")
if string.sub(dir, -1) == "/" then
dir=string.sub(dir, 1, -2)
end
local function yieldtree(dir)
for entry in lfs.dir(dir) do
if entry ~= "." and entry ~= ".." then
entry=dir.."/"..entry
local attr=lfs.attributes(entry)
coroutine.yield(entry,attr)
if attr.mode == "directory" then
yieldtree(entry)
end
end
end
end
return coroutine.wrap(function() yieldtree(dir) end)
end
An example use of code above:
for filename, attr in dirtree("D:\Test_Files\Outbound\Client\final") do
print(attr.mode, filename)
end
You have to check does extension equal to txt. To read file extension use this snippet:
function GetFileExtension(path)
return path:match("^.+(%..+)$")
end
So, to answer your question(s), you can get amount of files in directory just by counting elements in array returned in dirtree. To answer second question, just use code from the post. Table that you want is returned by dirtree(), but you may want to extract only .txt files from it. To read a file, just check other SO answers. You've got given name (in array), so use it.
EDIT: You can parse result of dir and ls command to get directory listing, but you shouldnt. Althrough this way you wouldn't need to install any libraries, your code is going to be heavily OS-depedent.
Adding libraries to your code isn't so bad. Hacking things is worse.
(Not sure file extension extracting function is going to work. I didn't make dirtree code used in this post, it belongs to David Kastrup)
I need to extract the object name from a sql text file. All of my sql files have as their 1st line "CREATE some type [schema name].[object name]. Sometimes the brackets are there, other times not. In either case, I need to be able to discern the object name affected so I can determine if it actually exists before updating the server with the new changes. I need to do this from a Windows 7 command line batch file. Not powershell, please.
Doing this in a batch file is a bit like working without your hands tied behind your back, but if you insist, I would suggest the following:
Get the first line of the file (you said in the comments that you can already do this).
Split the line on spaces and get the x-th value.
Split the resulting value on the dot.
Strip the backets from the value.
Voila. It won't be easy, it won't be readable, but it will do what you need and it will be a Windows cmd batch file.
I am trying to write a Visual Basic program that gets the names of all subdirectories within a directory, writes them into an array, and then writes the contents of the array to a dat file. I am however having a problem with the arrays not filling up with the directory names. Here's a piece of my code below.
For Each directoryName As String In IO.Directory.GetDirectories(appdata)
allAppdataDirectories(appdataNameId) = Dir(appdata)
appdataNameId += 1
ReDim Preserve allAppdataDirectories(appdataNameId)
Next
The above code snippet is supposed to get all of the directory names within my appdata folder. Assuming variable and array in this code has been declared already, what is wrong with it? I know that writing to the data file is working because I have done it in another context in this program and it works just fine.
You are not using the directoryName variable
Maybe it also would be easiest to use a list insted of an array
Check if this solution can work for you :
Dim allAppDataDirectories As New List(Of String)
For Each directoryName As String In IO.Directory.GetDirectories(appData)
allAppDataDirectories.Add(directoryName)
Next
'Finally, if you need an array you can use allAppDataDirectories.ToArray()
I am using clearmake and I am trying to do the following:
I have a Makefile.fast.options file that I use in my clearmake command. In there I have a USERFLAGS = -DFAST
and in another options file I don't have -DFAST in there (Makefile.slow.options).
In the actual Makefile, if FAST is defined, I want to set the output binary name to one name, or else I want to set it to another name. (If FAST is defined, I want the output to have .fast in the name, or else I want .slow.)
Is it possible to do this? perhaps I am missing a much easier method for using an options file to determine output file name?
I was also thinking of defining the filename in the makefile options file, seems much easier:
FILENAME = File.Fast
but I want to use the options file to override a definition of FILENAME thats in the makefile itself.. so, if FILENAME is set in the options file use it, or else use the one in the makefile.. is this possible?
You cannot just change the name of the file you build. You have to actually change the name of the target in the rule in the makefile. This means that the target name needs to be variable. The way you choose to make it variable is up to you.
If you're already including different options files based on fast vs. slow, then the simplest and most obvious way is to set the variable in those options files. That's the way I would recommend.
If you want to do it based on the value of USERFLAGS, you could do something like this:
ifeq ($(filter -DFAST,$(USERFLAGS)),-DFAST)
FILENAME = File.fast
else
FILENAME = File.slow
endif
But, this seems more complex and difficult to read and understand (to me).