Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename a group of .txt files dependent on first few 10 characters of Content

Status
Not open for further replies.

MattRichardsUK

Technical User
Dec 11, 2000
22
GB
Hi I have a problem where i have a folder with number of system generated .txt files that it names 00001.txt, 00002.txt etc currently on 05473.txt.

Each file has the descriptor for the file content as the first 10 characters of the firstline of said file.

I am trying to use SSIS to loop through the folder and read the first 10 chars from each .txt file and subsequently use thease first 10 chars to rename the file.

I thought this would be quite simple to achive but I find myself in a dark room banging my head against a wall as i try to think up a solution.

Any help on this would be greatly appreciated.

Regards
Mat
 
use script task.
inside script task read directoryInfo into array of all files with .txt extension after that loop throw array and reat each file and rename all in one task
 
Im sorry. now Im really lost is how should I read them into an array and rename
 
In script task you just use vb script or c# to read directory, file content or just first line and rename file...
this is article with code how to move all files from one directory to another
use from that link code to get all your files.

DirectoryInfo di = new DirectoryInfo(Dts.Variables["File_Dir"].Value.ToString());
FileInfo[] fi = di.GetFiles("*.txt");
and after that loop throw fi (array of files)
inside loop
1. read line from file
2. put your logic to create new file name
3. rename file (and move to new location)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top