|
#1
|
||||
|
||||
|
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 |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
||||
|
||||
|
Some tweaking, but got the job done with your help... Thanks again.
|
|
#5
|
||||
|
||||
|
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
__________________
Check out the new MSI Factory 2.0! |
|
#6
|
||||
|
||||
|
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! |
|
#7
|
||||
|
||||
|
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 |
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
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.








Linear Mode

