INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

(OP)
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

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

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

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

(OP)
Im sorry. now Im really lost is how should I read them into an array and rename

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

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
http://bicortex.com/how-to-programmatically-archiv...
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)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close