hello all ,

i'm new to C# and i have a problem, i created a program that categorize my files into folders and subfolders.

and i want to run a script test.bat that will run a python script to the files with extension .gb in the subfolders and this script will create a txt file containing the result for all the .gb files in the subfolder where the script is found,

so i placed a copy of test.bat inside each folder and subfolder and i saved the path of each one in a list ,

and after this i tried to loop the list of paths and run the script .

but it's not running as wanted , because all the txt files are created in the first folder with wrong results , but when i go to the folders and run the test.bat manually it gives the wanted results , but in the program , it's not working

soo i need your help plz

that's my code

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace Abdallah_Project
    public class Program
        static void Main(string[] args)
            List<String> list = new List<String>();
            //File.WriteAllText("test.bat", "python ../skew.py -e"+"A" +"-e"+"C" +"-e"+"G" +"-e"+"T"+ "*.gb -o test.txt");
           // String[] allfiles = null;
            int startColumnIndex, finishColumnIndex;
            Console.WriteLine("Enter the index of start column:");
            startColumnIndex = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the index of end column:");
            finishColumnIndex = int.Parse(Console.ReadLine());

            if (File.Exists("conf.txt") == false)
                throw new Exception("Configuration file not found");

            string[] confStr = File.ReadAllLines("conf.txt");

            for (int rowIndex = 0; rowIndex < confStr.Length; rowIndex++)
                string[] cells = confStr[rowIndex].Split(' ');

                if (startColumnIndex < 0 || finishColumnIndex > cells.Length - 1)
                    Console.Error.WriteLine(cells[0] + ", invalid column indexes");

                string fileName = cells[0] + ".gb";

                if (File.Exists(fileName) == false)
                    Console.Error.WriteLine(cells[0] + ", file not found");

                string newPath = "";
 File.WriteAllText("test.bat", "python C:\\Python27\\mtdb1\\src\\skew.py -e\"A\" -e\"C\" -e\"G\" -e\"T\" *.gb -o " + cells[finishColumnIndex] + ".txt");

                for (int columnIndex = startColumnIndex; columnIndex <= finishColumnIndex; columnIndex++)
                    if (Directory.Exists(cells[columnIndex]) == false)
                      Directory.CreateDirectory(newPath + cells[columnIndex] + "\\");
                    newPath += cells[columnIndex] + "\\";

                    if (File.Exists(newPath + "test.bat") == false)
                        File.Copy("test.bat", newPath + "test.bat");
                        list.Add(newPath + "test.bat");


                File.Move(fileName, newPath + fileName);
                Console.WriteLine(fileName + " -moved-> " + newPath + fileName);

                        int co = 0;
                     for (int i = 0; i < list.Count; i++) 


                     //Process pr = new Process();
            for (int i = 0; i < list.Count; i++) // Loop through List with for
                    Process pr = Process.Start(list[i]);
                    Console.WriteLine("File test path is " + list[i]);
                    //Console.WriteLine("Process is still running");
            Console.WriteLine("\n DONE ;) !!!");



i appreciate the help

6 Years
Discussion Span
Last Post by weblover
Process pr = new Process();
pr.StartInfo.FileName = list[i];
pr.StartInfo.WorkingDirectory = Path.GetDirectoryName(list[i]);
Votes + Comments
solved my problem ;)

thank you very much , this helped me alot and solved my problem

but i added this line in order to let them run in a sequence and not together

thank you alot :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.