Hello,
I need help to figure how to delete a file when it does not have a filename, per example:

Code:
using System;
using System.IO;
using System.Linq;
namespace FCCCU318SymitarPreprocessor
{
class Program
{
static void Main(string[] args)
{
if (args.Length > 0)
{
string inputFilePath;
string outputFilePath;
string inputFilePathOnly;
string fileToImport;
string strNewLine;
string reportID;
string reportName;
string reportDate;
string reportTime;
string FileName;
string FileTypeNum;
inputFilePath = args[0].ToString();
outputFilePath = args[1].ToString();
inputFilePathOnly = Path.GetDirectoryName(inputFilePath);
string inputFile = inputFilePath;
// Read Index.txt file
using (StreamReader sr = new StreamReader(inputFile))
{
string lineData;
lineData = sr.ReadLine();
while (!sr.EndOfStream)
{
lineData = sr.ReadLine();
if (lineData.Length > 6)
{
bool isError = false;
try
{
reportID = lineData.Substring(0, 6);
var isNumeric = reportID.All(c => "0123456789".Contains(c));
// if the reportId is numeric process the line
if (isNumeric)
{
// reportName is the OnBase DocType
reportName = lineData.Substring(7, 41).Trim();
if (reportName.Length > 1)
{
if (reportName.Length > 18)
{
if (reportName.Substring(0, 17).ToUpper() == "BATCH OUTPUT FOR ")
{
reportName = reportName.Substring(17);
}
}
reportDate = lineData.Substring(49, 8).Trim();
reportTime = lineData.Substring(61, 5).Trim();
FileTypeNum = "1"; // Assumption is that all the Symitar Reports are text
FileName = reportID; // Assumption is that the reportID will always be the file name without an extension
fileToImport = inputFilePathOnly + @"\" + FileName;
try
{
if (new FileInfo(fileToImport).Length > 0)
{
// reportName used for DocType and for the Report Name Keyword Type
// DocType hard coded to Symitar Reports Temp as DocType is assigned form the Report Name in the DocType Assignment Workflow
strNewLine = reportID + "|" + "FCCCUReports" + "|" + reportName + "|" + reportDate + "|" + reportDate + " " + reportTime + "|" + FileTypeNum + "|" + FileName;
using (StreamWriter sw = new StreamWriter(outputFilePath, true))
{
sw.WriteLine(strNewLine);
}
}
}
catch
{
isError = true;
}
}
}
}
catch
{
isError = true;
}
if (isError) continue;
}
}
Environment.ExitCode = 0;
}
}
}
}
}
Ivonne AspilcuetaPosted Jun 26, 2024, 3:41 PM
Thank you Rajeesh, but it is a little confuse here:
1) you said I need to check if the reportID property is null or an empty string before assigning it to FileName,
2) then you said run the code you provide as an enxample in my foreach loop?
Neither case worked.
Rajeesh MenothPosted Jun 26, 2024, 4:50 AM
Hi,
As per your code, the value of the FileName property is being assigned by the reportID property (FileName = reportID). Therefore, it is necessary to check if the reportID property is null or an empty string before assigning it to FileName property. Alternatively, you can also validate it with the FileName property as well.
Try this code: