I am trying to get a list of file names and their corresponding file sizes (files are on my local drive) onto an excel spreadsheet, I am able to get the file names listed onto the excel spreadsheet.
However, now for the next step, I have no idea on how to proceed: I think its the fact that I do not know the command/s for it? for example, how I need to utilise “System.IO.Path.GetFileName(item)” to get the file names - I just don’t know the file size equivalent. I have tried adding “.Length” to the end of “System.IO.Path.GetFileName(item)” but I keep getting some error.
If anyone could help me, I would appreciate it. Thanks!
as an alternate with a LINQ structured by Query Syntax and reduced by using Directory Info:
(From fi In New DirectoryInfo(strPath).GetFiles()
Let e = fi.Extension
Let n = fi.Name
Let s = fi.SizeInKB
Let lr = fi.LastWriteTime
Let ra = New Object(){n,e,lr,s}
Select dtResult.Rows.Add(ra)).CopyToDataTable
hi mate,
Thanks for the reply, is it possible to get the file size in Megabytes?
Other than that, the code works brilliantly.
Update: now im getting this: 08/29/2021 12:13:57 Assign: Input array is longer than the number of columns in this table. ← I recreated what I have done with one sequence that I always already working on.
How would I be able to “write” the excel spreadsheet to a “variable” folder?
Essentially, whenever the program is runned, an input dialog box pops up, I write in name, the name becomes associated to/as a variable. Once the folder is created, it would copy a set of files over into that folder and it would run the “excel” bit and create a file list of files within the folder. But the problem is I am not sure how to “write” the spreadsheet into a variable folder.
I tried something like this: “C:\Users\Media\Videos\Project+Name\FileList.xlsx”
but it did not work.
Also, with the file list, I open up the spreadsheet and it lists the files fine but the problem is Im not able to see the headings inserted “File names, file size, etc”