Indigo Rose Software
  #1  
Old 10-01-2004
GalacTek's Avatar
GalacTek GalacTek is offline
Forum Member
 
Join Date: Oct 2003
Location: Spring Hill, FL
Posts: 63
ASCI File data and rename files

We all know how great these tools are. I use them a lot for hammering fast utility issues that come up. What I am looking to do is read in a ASCII common delimited file and them renaming the file from the data. below is a sample of the data

"PatientID","First","Last","FileName"
"15","Steven","Johnson","2_3_0.TIF"
"15","Linda","Alexander","2_3_1.TIF"
"15","Linda","Alexander","2_3_2.TIF"
"15","Linda","Alexander","2_3_3.TIF"

Then I want to rename the Tif

2_3_0.TIF to 15_Steven_Johnson.TIF

Can anyone help me with reading in the data and creating the loop? Thanks in advance
Reply With Quote
  #2  
Old 10-02-2004
JXBURNS's Avatar
JXBURNS JXBURNS is offline
Forum Member
 
Join Date: Apr 2001
Location: Haverhill, Suffolk, UK
Posts: 333
I have not tested this but this is way I would do this although probably not perfect. Would have been easier if there had been a simple Awk parser or you had used something like the "|" character as a field delimiter.

Zipped up lua file attached as would not paste properly with indents here.

John
Attached Files
File Type: zip fileparseandrename.zip (861 Bytes, 8 views)
Reply With Quote
  #3  
Old 10-02-2004
GalacTek's Avatar
GalacTek GalacTek is offline
Forum Member
 
Join Date: Oct 2003
Location: Spring Hill, FL
Posts: 63
Thanks John... I will advised on Monday when I am back in the office. I agree on the field delimiter, but the format is from another products output and I have no contolr over it. Again thanks for you help and I will let you know how it goes.
Reply With Quote
  #4  
Old 10-04-2004
GalacTek's Avatar
GalacTek GalacTek is offline
Forum Member
 
Join Date: Oct 2003
Location: Spring Hill, FL
Posts: 63
Some tweaking, but got the job done with your help... Thanks again.
Reply With Quote
  #5  
Old 10-04-2004
Ted Sullivan's Avatar
Ted Sullivan Ted Sullivan is offline
Indigo Rose Staff Member
 
Join Date: Oct 2003
Posts: 825
John,

Just for future reference, in order to keep indents and spaces in forum post, you can use the "code" tags along with copy and paste into the forum.

Code:
-- This is some sample code
a = 5;
b = 7;
c = a*b;
if (c > 20) then
   d = 100;
else
   d = 200;
endif
This is done by enclosing your script between <code> script here </code>, but replacing the angle brackets < > with square brackets [ ].
__________________
Check out the new MSI Factory 2.0!
Reply With Quote
  #6  
Old 10-04-2004
Ted Sullivan's Avatar
Ted Sullivan Ted Sullivan is offline
Indigo Rose Staff Member
 
Join Date: Oct 2003
Posts: 825
Here is the original example:

Code:
-- Read the contents of a text file to a table.
text_contents = TextFile.ReadToTable("C:\\MyFile.txt");

-- Get the error code of the last action.
error = Application.GetLastError();

-- If an error occurred, display the error code message.
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
  NumberOfTableItems = Table.Count(text_contents);
  for j,k in text_contents do
  -- Ignore 1st line as contains headers
    if j>1 then 
	    LengthOfLine = String.Length(k);
	    StartOfField = true;
	    FieldCount = 0;
	    for x=1, LengthOfLine do
    	  Char2Test = String.Mid(k,x,1);
	      if Char2Test == String.Char(34) then
	      -- Char (34) is quotes
	        if StartOfField == true then
	        -- We are working within a field
	          FieldCount = FieldCount + 1;
	          StartOfField = false;
	        else
	        -- We have come to the end quote
	          if FieldCount < 4 then
	            if FieldCount ==1 then
	              NewFileName = FieldName;
	            else  
	              NewFileName = NewFileName + "_" + FieldName;
	            end  
	            FieldName = "";
	            StartOfField = true;
	          else
	            OldFileName = FieldName ;
	            -- Should now be at end of string  
	          end    
	        end
	      else
	        if StartOfField == false then 
	        -- Only add the character if working within a field to ignore the comma delimiters
	          FieldName=FieldName + Char2Test;  
	        end  
	      end  
	    end
	    -- Rename the file
	    File.Rename(OldFileName, NewFileName);
	
	    -- Get the error code of the last action.
	    error = Application.GetLastError();
	    -- If an error occurred, display the error code message.
	    if (error ~= 0) then
	        Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
	    end
	end    
  end  
end
__________________
Check out the new MSI Factory 2.0!
Reply With Quote
  #7  
Old 10-04-2004
JXBURNS's Avatar
JXBURNS JXBURNS is offline
Forum Member
 
Join Date: Apr 2001
Location: Haverhill, Suffolk, UK
Posts: 333
Ted,

Thanks for that. I run PHPBB on forums that I run on my server so was having problems inserting the variables I ususally use for that in this forum! Shall remember in future as knew it could be done as I had seen your previous examples..

Well at least the code appears to have worked anyway!

Rgds John
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me with a CD browser,please! Fabiana AutoPlay Media Studio 5.0 16 07-13-2004 11:42 AM
Incremental APMS5 projects files - workaround John_Klassek AutoPlay Media Studio 5.0 1 10-27-2003 10:21 AM
i want to convert my sound into data files... rpdigital AutoPlay Media Studio 4.0 6 11-06-2002 12:00 PM
INFO: ODBC Configuration Runtime Notes Support Setup Factory 6.0 Knowledge Base 0 10-30-2002 03:22 PM
HOWTO: "Hide" Externally Referenced Files Support AutoPlay Media Studio 4.0 Examples 0 10-23-2002 04:19 PM


All times are GMT -6. The time now is 04:51 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software