How to separate this
Moderators: JRL, Dorian (MJT support)
How to separate this
This is the content of "dirsize.txt"
-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 filename1.pdf
-rwxrwxrwx 1 owner group 729569 Sep 19 12:40 filename2.pdf
How do I use separate to get the "filename.pdf part to use for my script
thank you
ReadFile>%dir1%\dirsize.txt,data
Separate>data,Dates,filename
-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 filename1.pdf
-rwxrwxrwx 1 owner group 729569 Sep 19 12:40 filename2.pdf
How do I use separate to get the "filename.pdf part to use for my script
thank you
ReadFile>%dir1%\dirsize.txt,data
Separate>data,Dates,filename
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
Something like this should work for you:
Code: Select all
ReadFile>c:\temp\dirsize.txt,dirdata
//First separate the file into lines
Separate>dirdata,%CRLF%,dirfiles
If>dirfiles_count=0,end
//Loop through the lines
Let>k=0
Repeat>k
Let>k=k+1
//Then separate the line using a space for separator
Separate>dirfiles_%k%, ,filenames
//The file name is the 9th data element
MDL>filenames_9
Until>k,dirfiles_count
Label>end
Inconsistent result
-rwxrwxrwx 1 owner group 12456361 Sep 19 11:22 filename1.pdf
-rwxrwxrwx 1 owner group 729569 Sep 19 12:40 filename2.pdf
The result is not always at the 9th data element, if there are inconsistent in spacing in the 5th element.
is there a way to delete all the extra space and replace with just one space before we separate them out,
(it did not show in my post, but the real file has more space between the word "group" and the numbers)
thanks
-rwxrwxrwx 1 owner group 729569 Sep 19 12:40 filename2.pdf
The result is not always at the 9th data element, if there are inconsistent in spacing in the 5th element.
is there a way to delete all the extra space and replace with just one space before we separate them out,
(it did not show in my post, but the real file has more space between the word "group" and the numbers)
thanks
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Filename is always the last item. Therefore:
Code: Select all
Let>str=-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 filename1.pdf
Separate>str,SPACE,parts
Let>filename=parts_%parts_count%
MessageModal>filename
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Nice solution Marcus.
Here is another option:
Let>str=-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 filename1.pdf
Position>filename1.pdf,%str%,1,StartPos
MidStr>%str%,%StartPos%,20,filename
MessageModal>%filename%
But your solution is much better, do not need to know the name of the filename.
Here is another option:
Let>str=-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 filename1.pdf
Position>filename1.pdf,%str%,1,StartPos
MidStr>%str%,%StartPos%,20,filename
MessageModal>%filename%
But your solution is much better, do not need to know the name of the filename.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Thankyou that works for filename
but if I also wants to get the "byte" after the "group"
how can I do that
thanks
how can I do that
thanks
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Use the code from Marcus, with a simple change:
Let>str=-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 filename1.pdf
Separate>str,SPACE,parts
Let>groupID=%parts_5%
MessageModal>%groupID%
Check out the Help section for the Separate command to understand how the segments are numbered and counted as variables.
Let>str=-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 filename1.pdf
Separate>str,SPACE,parts
Let>groupID=%parts_5%
MessageModal>%groupID%
Check out the Help section for the Separate command to understand how the segments are numbered and counted as variables.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
There's a problem. If there are spaces within the filenames like this...mtettmar wrote:Filename is always the last item. Therefore:
Code: Select all
Let>str=-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 filename1.pdf Separate>str,SPACE,parts Let>filename=parts_%parts_count% MessageModal>filename
- -rwxrwxrwx 1 owner group 563682 Sep 19 11:22 file name 1.pdf
-rwxrwxrwx 1 owner group 729569 Sep 19 12:40 file name 2.pdf
Here's one solution...
Since there will never be a colon character : in the filename, we can break up the line using : as the delimiter instead of SPACE. The right-most piece will always start with the colon from the time value... like this for example:
- :22 file name 1.pdf
Code: Select all
Let>str=-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 file name 1.pdf
Separate>str,:,parts
Let>filename=parts_%parts_count%
MidStr>filename,6,1000,just_the_filename
Message>just_the_filename
Now as for parsing the "bytes after the group", here's one solution...
Code: Select all
Let>str=-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 file name 1.pdf
Separate>str,group ,parts
Let>line_starting_with_bytes=parts_%parts_count%
Separate>line_starting_with_bytes,SPACE,parts
Let>filename=parts_1
MessageModal>filename
After that, you just separate again, using SPACE as the delimiter only this time, what you are after is the first piece... not the last. Try it out, see if it works for you and let us know.
Can anyone find a shorter solution to the above?
P.S. Thanks Marcus for the Blog post on MS version 11 - much appreciated and looking forward to the beta!

Last edited by jpuziano on Sat Sep 27, 2008 6:29 am, edited 1 time in total.
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Just an idea, no code here yet.....
Two methods of dealing with the spaces:
1. Use VB RegEx to replace multiple spaces with a single space, will take care of any number of spaces between strings
OR
2. Use multiple lines of StringReplace, replacing double spaces with a single space. Maybe three lines in a row to take care of four or five spaces in a row.
Then use code from Marcus
Two methods of dealing with the spaces:
1. Use VB RegEx to replace multiple spaces with a single space, will take care of any number of spaces between strings
OR
2. Use multiple lines of StringReplace, replacing double spaces with a single space. Maybe three lines in a row to take care of four or five spaces in a row.
Then use code from Marcus
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Hi Bob,Bob Hansen wrote:Just an idea, no code here yet.....
Two methods of dealing with the spaces:
1. Use VB RegEx to replace multiple spaces with a single space, will take care of any number of spaces between strings
OR
2. Use multiple lines of StringReplace, replacing double spaces with a single space. Maybe three lines in a row to take care of four or five spaces in a row.
Then use code from Marcus
What would happen if there were three spaces in a row within the filename... like this for example:
file^^^name.txt
...where each ^ represents a space
If you do either 1 or 2 above, you would be altering the actual filename and perhaps not able to parse out the real filename which is "file^^^name.txt" (contains 3 spaces) not "file^name.txt" (contains only 1 space).
The code I posted also works for filenames that contain multiple spaces in a row:
Code: Select all
Let>str=-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 filenamecontains 3spaces.pdf
Separate>str,:,parts
Let>filename=parts_%parts_count%
MidStr>filename,6,1000,just_the_filename
Message>just_the_filename
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Regex to get the bytes:
This of course is a *nix directory listing. How is it being produced, because if you have control over this you could specify the ls parms to return the list in a different format that may not require parsing. E.g. the "ls" command can be set to only return the filenames. If this is from an FTP listing, FTPGetDirList can also be set to return only filenames.
Code: Select all
//DOES THE REGEX
VBSTART
Function regExSearch(strPattern,str)
Set regEx = New RegExp ' Create regular expression.
regEx.Pattern = strPattern ' Set pattern.
regEx.IgnoreCase = True ' Make case insensitive. Default=False
Set matches = RegEx.Execute(str)
List = ""
For each match in matches
List = List & match.value & ";"
Next
if List <> "" then
regExSearch = Mid(List,1,Len(List)-1)
end if
End Function
VBEND
Let>line=-rwxrwxrwx 1 owner group 563682 Sep 19 11:22 filename1.pdf
VBEval>regExSearch("group[\x20]*([0-9]{1,})\b","%line%"),bytes
StringReplace>bytes,group,,bytes
StringReplace>bytes, ,,bytes
MDL>bytes
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
For jpuziano
You are right if the filename might be split. But I did not see any indication from timle, or his samples, that "filename" would sometimes have a space character in the middle. My assumption was that filename.ext would not be split. Thanks for pointing out what would happen with a bad assumption. But, if the assumption is good, I think the multiple lines would work OK.Hi Bob,
What would happen if there were three spaces in a row within the filename... like this for example:
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
thank you for your help
I used tips from everyone to make a script to check the ftp to see if any files coming in and when it stop growing then download the file to local drive then remove it from the FTP
Thanks for all your help
Thanks for all your help