2
Answers

Rename file extensions in a unknown directory using c#

Mohan D

Mohan D

10y
868
1

I'm writing a code in C# and this is what i want to do:

  I want to change the extension of a file from ".txt" to ".jpg" . Bu this "txt" can be in any directory (so its a unknown directory). This it he path "C:\Users\username\Desktop\Convert" . So inside the convert folder there will be many other folders inside which there will be a ".txt" file (only one "txt" file will exist.). So the code should automatically change the extension of ".txt" file to ".jpg" . Please guide me
Answers (2)
0
Vulpes

Vulpes

NA 98.3k 1.5m 10y
Assuming all numeric columns are of type double, then try:

   foreach(DataRow dr in table1.Rows)
   {
      string colName = dr["Par Name"].ToString();
      if(table5.Columns.Contains(colName))
      {
         double lower = (double)dr["lower_limit"];
         double upper = (double)dr["upper_limit"];
         double min = table5.Rows.Cast<DataRow>().Min(r => r.Field<double>(colName));
             
         if (min >= lower)
         {
            double max = table5.Rows.Cast<DataRow>().Max(r => r.Field<double>(colName));
            if (max <= upper) table5.Columns.Remove(colName);
         }
      }
   }

or, if they're all strings, try:

   foreach(DataRow dr in table1.Rows)
   {
      string colName = dr["Par Name"].ToString();
      if(table5.Columns.Contains(colName))
      {
         double lower = double.Parse(dr["lower_limit"].ToString());
         double upper = double.Parse(dr["upper_limit"].ToString());
         double min = table5.Rows.Cast<DataRow>().Min(r => double.Parse(r.Field<string>(colName)));
             
         if (min >= lower)
         {
            double max = table5.Rows.Cast<DataRow>().Max(r => double.Parse(r.Field<string>(colName)));
            if (max <= upper) table5.Columns.Remove(colName);
         }
      }
   }

Accepted
0
Farhan Shariff

Farhan Shariff

NA 1.1k 111.4k 10y
Thank you vulpes . works perfect only  thing is I had to remove the last three columns from table5 (Split , Die_id and normal inverse), since I am adding it later again no problem :)
0
Khan Abrar Ahmed

Khan Abrar Ahmed

NA 5.8k 200k 10y
Hi,
what basis u want to match the rows?? please explain little bit more.