Using Wildcard in a File Rename - VisualCron - Forum

Community forum

itoperations@clicksquared.com
2015-11-13T21:30:34Z
I am using 7.6.0 and 7.7.0 and trying to rename a file using a couple of wildcards (*) and I am running into the following issue.

The file name is something like this:
LHNS_548_TEHN_GHESGY_CUSTOMER_20151113_060402.txt.5438082.REGISTERED

and I am trying to drop everything after the .txt, so it should wind up like this:
LHNS_548_TEHN_GHESGY_CUSTOMER_20151113_060402.txt

I tried in both File Copy and Rename File to use various combinations similar to this:
{STRING(Replace|{NEWNAME()}|*.txt.*.REGISTERED|*.txt)}

The Copy File task (with the post process mask) runs without error, or output, and does not rename the file.
The Rename File task outputs the following error and fails, deleting the file it is trying to rename

Exception in Task: System.ComponentModel.Win32Exception (0x80004005): Error 2 moving file '\\server\556\LHNS_548_TEHN_GHESGY_CUSTOMER_20151113_060402.txt.5438082.REGISTERED' to '\\server\556\LHNS_548_TEHN_GHESGY_CUSTOMER_20151113_060402.txt.5438082.REGISTERED': The system cannot find the file specified.
at ZetaLongPaths.ZlpIOHelper.MoveFile(String sourceFilePath, String destinationFilePath)
at OBOKIIHBDBPMCFALPGECCIFHCDJPEDKODDGK.ECJDHCFCEOFKDAGEFAFFFJFBNMDKFHIGHBOM.ONHALLOJFJGKIGDKOCPOCLFCDLKADGGGHFDP() in C:\sourcefiles\code\VisualCronService\Jobs\TaskProcesses\File\clsProcessTaskFileRename.vb:line 62

When I use something like this,
{STRING(Replace|{NEWNAME()}|.REGISTERED|.txt)}
The .REGISTERED is replaced with .txt, as expected. However, this of course leaves me with the numbers that I still need to remove.

Am I just missing some way of enclosing the wildcard or something?

Thanks,
ErikC
2015-11-16T09:44:39Z
Hi,

The wildcard can have some difficulties to rename a file like this, but... there is an other way you can use ;-)

Use in the post process mask the following line:

{REGEX(MatchGetGroup|{NEWNAME()}|(.+\.txt)\.[0-9]+\.REGISTERED|1)}


What this does is using regular expression to match a path of your filename:

.+\.txt matches your filename without the number and REGISTERED part. When using parenthesis around this, you mark it as a group.
So you have (.+\.txt) Next you have to complete the regular expression and I did this by \.[0-9]+\.REGISTERED, what is a dot followed by numbers, a dot and REGISTERED at the end.

So this is your filename with one group in there: (.+\.txt)\.[0-9]+\.REGISTERED
With the MatchGetGroup, you can get this 1st group out of it, and using the number 1 for the 1st group you end up with the filename without the .numbers.REGISTERED

You do not need to use the last file trigger variable but the NEWNAME() is fine ( you could if you would, though).

Regards,
Erik
Uses Visualcron since 2006.
ErikC
2015-11-16T09:58:07Z
Hi (again),

If you just want the filename without the date time stamp in there you can use the same methodology.
Use this regular expression in stead. The parenthesis are aroud the real filename and you can get it with the matchgroup:

(.+)_[0-9]+_[0-9]+\.txt\.[0-9]+\.REGISTERED

You end up with: LHNS_548_TEHN_GHESGY_CUSTOMER (you have to add a .txt after the post progress mask) :

{REGEX(MatchGetGroup|{NEWNAME()}|(.+\.txt)\.[0-9]+\.REGISTERED|1)}.txt


Regards,
Erik
Uses Visualcron since 2006.
itoperations@clicksquared.com
2015-11-16T17:53:33Z
Erik,
Your 1st mask worked perfectly. I was killing myself trying to figure out why the wildcards were not working.
Thanks!
Scroll to Top