Jump to content
Macro Express Forums

Text File Process


cyberchief

Recommended Posts

I am not very versed in the text file processing abilities... so here goes a question. I need Macro to look into a specific folder for a file. We will be having an on-line site generating text file submissions to this folder. The File name will change with every submission... I want macro to look into the folder and find the earliest file created date and process that text file. In the coding, I will have macro copy that file to another folder and rename... so there will be no worries about duplicating that project. But how do I find the earliest created text file and have macro recognize that one to run the text file process? Thanks!

Link to comment
Share on other sites

Hello David!

 

This is easier than the code below looks. You can use the Variable Set from File Date/Time command to get the creation time of a file. Each element (Month, Day, Year, Hour, Minute, Second) is placed into a separate integer variable.

 

In order to generate a singe comparison string of these elements, leading zeros (or lack thereof) must be handled. That is what the Convert, Pad Left, and Replace string commands do.

 

Once the leading zeros are inserted then the elements are concatenated into a single string, which is used to compare the elements of the next file in the loop. If the next file date string is less than the current file date string, then it becomes our "least date" string, and the file name itself is copied and held.

 

So by the time you get to the end of the Repeat with Folder loop, you will have the file name that was created the earliest.

 

Now you just need to add the code to copy that file to your other folders.

 

// Set the initial "least date" comparison string to the maximum value.
Variable Set String %T9% "99999999999999"

// Loop through all files in the source folder.
Repeat with Folder
 
 // Get the creation date/time elements of this file.
 Variable Set From File Date/Time
 
 // Add-in the leading zeros.
 Variable Modify Integer: Convert %N10% to text string %T10%
 Variable Modify Integer: Convert %N11% to text string %T11%
 Variable Modify Integer: Convert %N12% to text string %T12%
 Variable Modify Integer: Convert %N13% to text string %T13%
 Variable Modify Integer: Convert %N14% to text string %T14%
 Variable Modify Integer: Convert %N15% to text string %T15%
 Variable Modify String: Pad Left %T10%
 Variable Modify String: Pad Left %T11%
 Variable Modify String: Pad Left %T13%
 Variable Modify String: Pad Left %T14%
 Variable Modify String: Pad Left %T15%
 Replace " " with "0" in %T10%
 Replace " " with "0" in %T11%
 Replace " " with "0" in %T13%
 Replace " " with "0" in %T14%
 Replace " " with "0" in %T15%
 
 // Comparison the elements with the current "least date" string.
 Variable Set String %T16% "%T12%%T10%%T11%%T13%%T14%%T15%"
 If Variable %T16% < variable %T9%
   Variable Modify String: Copy %T16% to %T9%
   Variable Modify String: Copy %T1% to %T7%
 End If
Repeat End


<REM2:><REM2:Set the initial "least date" comparison string to the maximum value.><TVAR2:09:01:99999999999999><REM2:><REM2:Loop through all files in the source folder.><REP3:07:000002:000001:0001:0:01:c:\images><REM2:><REM2:Get the creation date/time elements of this file.><VFFILE:0:0:T:10:T:11:T:12:T:13:T:14:T:15:%T1%><REM2:><REM2:Add-in the leading zeros.><NMVAR:05:10:0:0000010:0:0000000><NMVAR:05:11:0:0000011:0:0000000><NMVAR:05:12:0:0000012:0:0000000><NMVAR:05:13:0:0000013:0:0000000><NMVAR:05:14:0:0000014:0:0000000><NMVAR:05:15:0:0000015:0:0000000><TMVAR2:14:10:00:002:000:><TMVAR2:14:11:00:002:000:><TMVAR2:14:13:00:002:000:><TMVAR2:14:14:00:002:000:><TMVAR2:14:15:00:002:000:><TMVAR2:21:10:00:000:000: 0><TMVAR2:21:11:00:000:000: 0><TMVAR2:21:13:00:000:000: 0><TMVAR2:21:14:00:000:000: 0><TMVAR2:21:15:00:000:000: 0><REM2:><REM2:Comparison the elements with the current "least date" string.><TVAR2:16:01:%T12%%T10%%T11%%T13%%T14%%T15%><IFVAR2:4:16:3:T9><TMVAR2:09:09:16:000:000:><TMVAR2:09:07:01:000:000:><ENDIF><ENDREP><REM2:>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...