Excel VBA list files from a URL - url

Ok, how would I hist all the files in a folder that is located on a remote server that I have to access using a URL e.g. http://domain.com/folder and inside the folder there are a bunch of files that I would like listing into excel. There are functions do this when trying to list files in a folder that are on your current C:\ but they don't work when trying to list files from a URL. I am not sure if this can be done! Thanks

Map the server directory as a local drive on your machine (e.g. O:) and use a small VBA procedure, e.g.
Sub ServerDir()
Dim Idx As Integer, FN As String, R As Range
Set R = Selection
Idx = 1
' URL = http://repository.XXXXX.com/content/dav/Repository/Users/Users-M/mike.d/mike.d-Public/
' mapped http://repository.XXXXX.com/content/dav/ to O:\
FN = Dir("O:\Repository\Users\Users-M\mike.d\mike.d-Public\*.ppt")
Do While FN <> ""
R(Idx, 1) = FN
FN = Dir()
Idx = Idx + 1
Loop
End Sub

Related

LUA: How to Create 2-dimensional array/table from string

I see several posts about making a string in to a lua table, but my problem is a little different [I think] because there is an additional dimension to the table.
I have a table of tables saved as a file [i have no issue reading the file to a string].
let's say we start from this point:
local tot = "{{1,2,3}, {4,5,6}}"
When I try the answers from other users I end up with:
local OneDtable = {"{1,2,3}, {4,5,6}"}
This is not what i want.
how can i properly create a table, that contains those tables as entries?
Desired result:
TwoDtable = {{1,2,3}, {4,5,6}}
Thanks in advance
You can use the load function to read the content of your string as Lua code.
local myArray = "{{1,2,3}, {4,5,6}}"
local convert = "myTable = " .. myArray
local convertFunction = load(convert)
convertFunction()
print(myTable[1][1])
Now, myTable has the values in a 2-dimensional array.
For a quick solution I suggest going with the load hack, but be aware that this only works if your code happens to be formatted as a Lua table already. Otherwise, you'd have to parse the string yourself.
For example, you could try using lpeg to build a recursive parser. I built something very similar a while ago:
local lpeg = require 'lpeg'
local name = lpeg.R('az')^1 / '\0'
local space = lpeg.S('\t ')^1
local function compile_tuple(...)
return string.char(select('#', ...)) .. table.concat{...}
end
local expression = lpeg.P {
'e';
e = name + lpeg.V 't';
t = '(' * ((lpeg.V 'e' * ',' * space)^0 * lpeg.V 'e') / compile_tuple * ')';
}
local compiled = expression:match '(foo, (a, b), bar)'
print(compiled:byte(1, -1))
Its purpose is to parse things in quotes like the example string (foo, (a, b), bar) and turn it into a binary string describing the structure; most of that happens in the compile_tuple function though, so it should be easy to modify it to do what you want.
What you'd have to adapt:
change name for number (and change the pattern accordingly to lpeg.R('09')^1, without the / '\0')
change the compile_tuple function to a build_table function (local function build_tanle(...) return {...} end should do the trick)
Try it out and see if something else needs to be changed; I might have missed something.
You can read the lpeg manual here if you're curious about how this stuff works.

Global Variables to text file

I'm trying to loop through all the globals and save them to a text file but I unable to do since io.write won't automatically convert to string. Just trying to figure out how I can do this with the simplest way possible.
for k,v in pairs(_G) do
print("Global", k, "value", v)
io.open("test.txt", "a")
io.write("Global", k, "value", v, "\n")
end
io.open opens a file and returns a file handle. You use that handle for writing. You only open the file once, and you have to close it afterwards. The code should look more like this:
f = assert (io.openĀ ("test.txt", "a")) -- open file
for k, v in pairs (_G) do
f:write ("Global: ", tostring (k), " = value: ", tostring (v), "\n")
end
f:close () -- done with file
Note that your code appends to an existing file. You may not want that. If not, change "a" to "w".

Read images from local disk using torch7 while those images saved in different subfolders?

I have images which have saved in the desk. The data saved as follow: 4 main folders (1,2,3 and 4) each folder has 26 subfolders ( these subfolders represent the class of images (A, B, C, D, ..,Z)). Each of these subfolder contains more than 500 images. However, I am looking for file or code in torch that can read these images. In MATLAB I could wrote a code but here I find it confuse. Could you please advise me.
What you can do is use Penlight (the library is installed when you install Torch).
Penlight provides pl.dir that makes it easy to scan files in (sub-)folders. For example what you can do is:
local pl = require('pl.import_into')()
local t = {}
for i,f in ipairs(pl.dir.getallfiles('/data/foo', '*.jpg')) do
t[i] = { f, pl.path.basename(pl.path.dirname(f)) }
end
This creates a list of pairs (filename, class label = "A" or "B" ...). Of course you are free to change the file pattern (*.jpg) or to omit it (in such a case Penlight will simply list all files). You can also load the images on the fly:
t[i] = { image.load(f), pl.path.basename(pl.path.dirname(f)) }
Or do that right after when manipulating t.

Lua: read a file

I am using lua to read the data in file, and this code is shown as below,
filename = "./temp/vtx_vel"..id..".dat"
file = io.open(filename, "r")
lineno = i + ni*j
local n = -1
for l in io.lines(filename) do
n = n + 1
if n == lineno then
vel = tonumber(l)
break
end
end
file:close()
The data in the external file is changing. However, it's quite strange to me that I got the same value when reading this file at different steps. Why is that?
Thank you.
The best way to read a file from my experience is to just do this:
local f = io.open(--your file here)
local output = {}
for each in f:lines() do
output[#output+1] = each
end
Your file will be read into the table output.
Something else to note, unless you define a mode, io.open() opens a file by default in "r" or read mode.

Ant flaka: modify each elements of a list

I have this list:
<c:let>
a = list('a','b','c')
</c:let>
How can i modify each elements for that list?
I need something like:
for (int i = 0; i < a.length; i++) {
a[i] += 'd';
}
I looked in the tutorial, but the examples show only how to retrieve a list element, not how to modify it.
So, how can i modify list elements, iterating on it?
Thanks!
There is (currently) no function which lets you manipulate lists. All you could do is
<let>
a = list('a', 'b', .. ) ; your list
b = list() ; empty list
</let>
<for var=" item " in=" a ">
<let>
x = some-el-expression( item ) ;
b = append(b, x)
</let>
</for>
<let>
a = b
</let>
Work has started which allows one to use functions with arguments - besides the convenience functions (append() and other functions listed in section 3.6 of the manual). Other work has also been started to allow you to plugin your own functions (would require Java programming - providing functions via Groovy or (J)Ruby needs some research).

Resources