I have a folder that contains x amount of files with different extensions, I need a way to retrieve all the files with the name 0000001 regardless of their extension, i then have to work with these and then retrieve all files with the name 0000002. I know I can increment the filename variable but when the file name becomes 0000010 how do I keep it the same amount of digits when incrementing, will it just add an extra digit such as 00000010.

So far I am accessing the files and saving them all in an array

 String[] files = Directory.GetFiles(@"D:\test\ElectionFiles");

and then looping through each file and pulling the information from it and sending it to the database

 foreach (String fi in files)
            {
                FileInfo f = new FileInfo(fi);
                string filename = f.Name;

                XmlDocument doc = new XmlDocument();
                doc.Load(fi);
                string document = doc.InnerXml;

                SqlCommand cmd = new SqlCommand("submit");
                cmd.Parameters.AddWithValue("@document", document);
                cmd.Parameters.AddWithValue("@filename", filename);
                cmd.Parameters.Add(new SqlParameter()
                {
                    ParameterName = "RETURN_VALUE", 
                    Direction = ParameterDirection.ReturnValue

                });
            }

Just want some advice if this looks correct and how I can go about only retrieving the 4 files at a time and how I can increment the filename to retrieve the correct files.

Thanks

Keep track of which number you're looking for in an integer variable, not a string, and use custom numeric formatting to turn that into a file serach spec with the correct number of zeros. Then you can just increment the integer variable and not have to worry about rolling the digits up yourself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.