Operators.ConcatenateObject()

GEGlad emoji10/31/2022
Looking for a replacement for the method. i c#

This Method comes from vb
https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.compilerservices.operators.concatenateobject?view=net-7.0

But is there something else I can use?
DDoktor910/31/2022
Why do you want to concatenate objects? That makes little sense
DDoktor910/31/2022
Then they want to concat strings, you're right. For objects it would only make sense in a language like JavaScript where doing so would concat 2 associative arrays
DDoktor910/31/2022
Oh man, framework source is damn ugly in VB
GEGlad emoji10/31/2022
Hi,
Got an old project in my lap at work that my boss wants me to rebuild with newer technology. He means write it in csharp and not in vb haha.
GEGlad emoji10/31/2022
I want to Check lastActivity folder and file name
GEGlad emoji10/31/2022
 sLastActivity = "Create object oFso"
    Set oFso = CreateObject("Scripting.FileSystemObject")
  
    'Search certificate source folder for pdf files and archive files
    Set oFolder = oFso.GetFolder(sReportSourceRootFolder)
    Set oFiles = oFolder.Files
    For Each oFile In oFiles 'Take all pdf-files first
        sLastActivity = "report " & oFile.Name
        'Pdf-files: copy pdf and archive
        If oFile.DateLastModified < (Now() - 0.05) And LCase(oFso.GetExtensionName(oFile.Path)) = "pdf" And Not Left$(oFile.Name, 1) = "~" Then
            sLog = sLog & vbCrLf & oFile.Name & " Rep"
            If CopyToMioArchive(oFile.Path) Then Archive oFile.Path, sReportDestRootFolder
        End If
    Next
GEGlad emoji10/31/2022
trying to convert this to c# 🙂
GEGlad emoji10/31/2022
Set oFiles = oFolder.Files =

LastActivity = Operators.ConcatenateObject("file", File);

But then I need to install And I do not what to do that
Image
GEGlad emoji10/31/2022
Can I write it like this?

LastActivity = String.Concat("report", File);
Ddancepanda4210/31/2022
how should last activity look like?
"report" and the file name or the complete file path?
GEGlad emoji10/31/2022
Just the report and the filename.
I have the filepath
GEGlad emoji10/31/2022
It is a automating file archive system.
It looks for three folders and looks for files that are 1 hour and moves the files to a other folder like a Archive.
Ddancepanda4210/31/2022
var folders = new string[]
{
    "Path\\to\\first\\folder",
    "Path\\to\\second\\folder",
    "Path\\to\\third\\folder",
};

foreach(var file in folders.SelectMany(x => Directory.GetFiles(x)))
{
    var fileInfo = new FileInfo(file);
    if (fileInfo.Extension == ".pdf" &&
        fileInfo.LastWriteTime < DateTime.Now - TimeSpan.FromMilliseconds(500) && 
        !file.StartsWith("~"))
    {

        // Do your stuff here...
        LastActivity = $"report{fileInfo.Name}";
    }
}
Ddancepanda4210/31/2022
here a little code snipped how it could work... (not tested)
GEGlad emoji10/31/2022
Nice, Looks like the one I am write right now but yours was so much better 🙂
GEGlad emoji10/31/2022
Thank you for you help.
Ddancepanda4210/31/2022
no problem
in C# there is also a lot of code sugar
DDoktor910/31/2022
Shouldn't you be using Path.Combind instead of interpolation? Or is "report" part of the filename?
Ddancepanda4210/31/2022
As I see it the variable LastActivity is only used to display the current process and is not used for file processing.
Otherwise you are right, Path.Join or Path.Combine would be the right choice.
DDoktor910/31/2022
OK
GEGlad emoji10/31/2022
This is my result
  string[] AttachmentFiles = Directory.GetFiles(ReportSourceRootFolder, "*.pdf", SearchOption.AllDirectories);
        LastActivity = String.Concat("report", AttachmentFiles);
        foreach (string AttachmentFile in AttachmentFiles)
        {
            var fileInfo = new FileInfo(AttachmentFile);
            if (File.GetLastWriteTime(AttachmentFile) < DateTime.Now - TimeSpan.FromMilliseconds(500) && fileInfo.Extension == ".pdf" && !AttachmentFile.StartsWith("~"))
               {
                 Archive(AttachmentFile, AttachmentDestRootFolder);
               }
        }
GEGlad emoji10/31/2022
How come my code snippes do not look like yours @dancepanda42 ?
Ddancepanda4210/31/2022
There are many ways that lead to the target.
You can omit the query
fileInfo.Extension == ".pdf"
because of the filter in
Directory.GetFiles(ReportSourceRootFolder, "*.pdf", SearchOption.AllDirectories);
.
What is the variable LastActivity needed for anyway?
Ddancepanda4210/31/2022
behind the three "`" comes a csharp
GEGlad emoji10/31/2022
Its for the writing in the logging file later in the code.

 LastActivity = "Writing log file";
        Log = Log + Environment.NewLine + "RoboArchiveManager finished at " + DateTime.Now.ToString() + Environment.NewLine + Environment.NewLine;
        File.WriteAllText(FileLog, Log);
Ddancepanda4210/31/2022
Image
GEGlad emoji10/31/2022
 LastActivity = "Writing log file";
        Log = Log + Environment.NewLine + "RoboArchiveManager finished at " + DateTime.Now.ToString() + Environment.NewLine + Environment.NewLine;
        File.WriteAllText(FileLog, Log);
Ddancepanda4210/31/2022
it needs a new line after csharp
GEGlad emoji10/31/2022
Nice
GEGlad emoji10/31/2022
So do you code for a living or for hobbies?
Ddancepanda4210/31/2022
living
Ddancepanda4210/31/2022
but starts with hobby
Ddancepanda4210/31/2022
for the Log variable I would recommend a StringBuilder. This is not as computationally intensive as an extension of a string.
GEGlad emoji10/31/2022
Same.

Okej Thanks for the tips.
Started working about 1 year ago.

But man o man a lot more to learn haha
Ddancepanda4210/31/2022
or just use the File.AppendAllText method instead of the Log variable
GEGlad emoji10/31/2022
Okej will try that 🙂 Thank you for taking your time helping me 🙂
GEGlad emoji10/31/2022
  'Create objects
    sLastActivity = "Create object oFso"
    Set oFso = CreateObject("Scripting.FileSystemObject")
GEGlad emoji10/31/2022
This bit is little wired.

What will happen if I write

LastActivity = "Create object Fso";

        object? Fso = Activator.CreateInstance(Type.GetTypeFromProgID("Scripting.FileSystemObject")); 
GEGlad emoji10/31/2022
I do not know that its for
DDoktor910/31/2022
You shouldn't need a FileSystemObject. It looks like you only use it to get a directory, which can be done in a better way
DDoktor910/31/2022
You already use Directory.GetFiles to get the files in a directory, what else am I missing the oFso does?
GEGlad emoji10/31/2022
Yes I do not need LastActivity,

What I was trying to do is Finding folder then files in folder but do not need LastActivity
GEGlad emoji10/31/2022
Yes thats true. In the old code oFso is use to GetExtenstionName(FilePath)
GEGlad emoji10/31/2022
But I am getting that from Directory
DDoktor910/31/2022
You won't and shouldn't normally need to use reflection, i.e. CreateInstance
GEGlad emoji10/31/2022
Funny thing is that when I got the assignment I found Telerik code converter so I thought that this will be a easy task haha
DDoktor910/31/2022
Code converters are always dodgy
GEGlad emoji10/31/2022
Yes they are. Had some help but you two had helped me a lot to day. I appreciate that 🙂
GEGlad emoji10/31/2022
And been writing all day and I am so happy that I order and got my new mouse and keyboard last week
GEGlad emoji10/31/2022
Image
GEGlad emoji10/31/2022
My mommy always told me that a good programmer has Logi hahah