Need program to rename

#1
Hi trading universe..
If there is a skilled programmer out there i request u can u code
the following requirement

there is batch of files called f1 to f10 all csv what i want is

data look like
f1.csv
Code:
Trading Symbol,Time,Open,High,Low,Close/Price,Volume
NIFTY15JULFUT,29-07-2015 15:30:00,8382.4500,8382.4500,8382.4500,8382.4500,850
NIFTY15JULFUT,29-07-2015 15:29:00,8381.0000,8382.9500,8380.7000,8382.3000,132250
NIFTY15JULFUT,29-07-2015 15:28:00,8379.3500,8382.0000,8379.2500,8381.0000,122800
NIFTY15JULFUT,29-07-2015 15:27:00,8377.4500,8379.4500,8377.0000,8379.2500,75425
NIFTY15JULFUT,29-07-2015 15:26:00,8376.9000,8377.5000,8375.0500,8377.0000,56025
i want program to read the last line of the file and rename the file f1.csv to NIFTY15JULFUT.csv i.e (Trading Symbol)

Many thanks in advance
 

rkkarnani

Well-Known Member
#2
Hi trading universe..
If there is a skilled programmer out there i request u can u code
the following requirement

there is batch of files called f1 to f10 all csv what i want is

data look like
f1.csv
Code:
Trading Symbol,Time,Open,High,Low,Close/Price,Volume
NIFTY15JULFUT,29-07-2015 15:30:00,8382.4500,8382.4500,8382.4500,8382.4500,850
NIFTY15JULFUT,29-07-2015 15:29:00,8381.0000,8382.9500,8380.7000,8382.3000,132250
NIFTY15JULFUT,29-07-2015 15:28:00,8379.3500,8382.0000,8379.2500,8381.0000,122800
NIFTY15JULFUT,29-07-2015 15:27:00,8377.4500,8379.4500,8377.0000,8379.2500,75425
NIFTY15JULFUT,29-07-2015 15:26:00,8376.9000,8377.5000,8375.0500,8377.0000,56025
i want program to read the last line of the file and rename the file f1.csv to NIFTY15JULFUT.csv i.e (Trading Symbol)

Many thanks in advance
Not sure if this would serve your purpose :
http://www.bulkrenameutility.co.uk/Main_Intro.php

I use this utility for renaming MP3 files that have numeral in their prefix making it difficult to make them alphabetical.
 

VJAY

Well-Known Member
#3
Hi trading universe..
If there is a skilled programmer out there i request u can u code
the following requirement

there is batch of files called f1 to f10 all csv what i want is

data look like
f1.csv
Code:
Trading Symbol,Time,Open,High,Low,Close/Price,Volume
NIFTY15JULFUT,29-07-2015 15:30:00,8382.4500,8382.4500,8382.4500,8382.4500,850
NIFTY15JULFUT,29-07-2015 15:29:00,8381.0000,8382.9500,8380.7000,8382.3000,132250
NIFTY15JULFUT,29-07-2015 15:28:00,8379.3500,8382.0000,8379.2500,8381.0000,122800
NIFTY15JULFUT,29-07-2015 15:27:00,8377.4500,8379.4500,8377.0000,8379.2500,75425
NIFTY15JULFUT,29-07-2015 15:26:00,8376.9000,8377.5000,8375.0500,8377.0000,56025
i want program to read the last line of the file and rename the file f1.csv to NIFTY15JULFUT.csv i.e (Trading Symbol)

Many thanks in advance
you mean renaming ?...then I do it note pad...edit>find&replace>enter what youwant to replace...
 
#4
i mean application must read last line first 13 char and then rename the file name to it..

well currently manually can be done but still

i ahve like 10 files f1 f2 f3 f3 each is of different symbol like 8700 CE 8800CE 8900CE

suppose f2 has 8800 CE data

so i want a program that can read values in f2.csv i.e (NIFTY158800CE) and copy that and rename the file to
NIFTY158800CE.csv
 

Raghuveer

Well-Known Member
#6
Check if this would be helpful

http://www. 4shared. com/ file / scjqvtOFce / CSVFileRenamer.html

its a small command line utility that renames all csv file in the folder to the first word of the last line in a comma separated file
Thanks. Is it possible to post/upload the source code?
 
#7
Thanks. Is it possible to post/upload the source code?
That was just a 5 minute task. Anyone else could have done it better. But this is what I did. See if this helps

Code:
try
            {           
            string path = Directory.GetCurrentDirectory();
            string[] FileArray = Directory.GetFiles(path, "*.csv"); 
                if (FileArray.Length > 0)
                {
                    foreach (string name in FileArray)
                    {
                        var lines = File.ReadLines(name);
                        string line = lines.Last();
                        if (!String.IsNullOrEmpty(line))
                        {
                            string[] fields = line.Split(',');
                            if (fields.Length >= 0)
                            {
                                string newFileName = path + "\\" + fields[0] + ".csv";
                                File.Move(name, newFileName); // Rename the oldFileName into newFileName
                            }
                            else
                            {
                                Console.WriteLine("Not a valid comma seperated file");
                                Console.ReadLine();
                            }
                        }
                        else
                        {
                            Console.WriteLine("No data found in file");
                            Console.ReadLine();
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No CSV Files found in the current folder");
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
 
#8
Last edited:

Similar threads