Page 1 of 1
ExecuteCommand()
Posted: Thu Sep 29, 2011 6:17 am
by mags88
Hi,
Just a quick question regarding ExecuteCommand() TI function. I'm trying to move a file between one location to another. The function works perfectly when I type in the file in the source folder. I would like to add a variable to ExecuteCommand() function instead of the exact file name. To clarify:
Code: Select all
ExecuteCommand('robocopy /move c:\origin c:\destination TestA.txt', 0);
This works fine. I would like to do the following:
Code: Select all
vFileName = 'TestA.txt';
vCmd = 'robocopy /move c:\origin c:\destination vFilename';
ExecuteCommand(vCmd,0);
The process runs fine, it just doesn't move the file TextA.txt. I've concluded, it is because instead of reading vFileName as a variable, the process searches for a filename that corresponds to vFileName in the origin folder and obviously no file is found to match that search criterion.
What puzzles me is that you can add a variable (vCmd) to the ExecuteCommand() function but you cannot add the variable (vFilename) to robocopy. Is there a way to move the file using the ExecuteCommand() function using variables instead of the exact file name. The reason I want to use variables instead of the exact file name is because this ExecuteCommond() function is going to be at the end part of a loop that will move the files after the T.I. has finished with them.
Regards,
Magnus
Re: ExecuteCommand()
Posted: Thu Sep 29, 2011 6:34 am
by Gregor Koch
You can either try this
vCmd = 'robocopy /move c:\origin c:\destination ' | vFilename;
Edit: Sorry was missing a space after destination in the code
This will concatenate the two parts of your command string rather than trying to copy to the file 'vFilename'.
Or you can parametrise a batch file that sits outside TM1, the former is probably easier as you are almost there.
Cheers
Re: ExecuteCommand()
Posted: Fri Sep 30, 2011 1:04 am
by mags88
Hi Gregor,
Using the concat function just creates a new destination folder called [original destination]|[filename]. The robocopy /move also moves everything that is in the origin folder into the new folder (as the function doesn't see a source file to copy). I am also trying to get the batch file method to work too, but the similar problem arises. I want the batch file to just move one file not all files in the origin folder.
Could anyone help me with the correct terminology to use, so that batch file picks up only one file (a bit like what wildcardfilesearch function does in TI.) Using the wildcard *, it searches for the first file after the wildcard and not all. Currently my batch file moves all files in the folder into a new folder. Again I do not want to code in the full filename for my batch file, as it will be used in a TI WHILE process and I will not know the full name or how many files there will be.
Regards,
Magnus
Re: ExecuteCommand()
Posted: Fri Sep 30, 2011 2:37 am
by tomok
mags88 wrote:Could anyone help me with the correct terminology to use, so that batch file picks up only one file (a bit like what wildcardfilesearch function does in TI.) Using the wildcard *, it searches for the first file after the wildcard and not all. Currently my batch file moves all files in the folder into a new folder. Again I do not want to code in the full filename for my batch file, as it will be used in a TI WHILE process and I will not know the full name or how many files there will be.
Perhaps you should Google for help on Robocopy?????
Re: ExecuteCommand()
Posted: Tue Oct 04, 2011 12:02 am
by Gregor Koch
Hi
If your example code is working and you use my code, including the space/blank, I don't see how this shouldn't be working.
Maybe post the real folder names, file name and code you are using, as something might get lost in translation.
Other than that... same as what tomok said.
Cheers
Re: ExecuteCommand()
Posted: Tue Oct 04, 2011 1:57 am
by rmackenzie
Without seeing the real filenames etc, we are only guessing!... Perhaps you should use this code, just in case your variable filenames have spaces in their paths:
Code: Select all
vFileName = 'c:\something like\this sort of\filename\with spaces.txt';
vQuotedFileName = CHAR(34) | vFileName | CHAR(34);
vCmd = 'robocopy /move c:\origin c:\destination ' | vQuotedFilename';
ExecuteCommand(vCmd,0);
Re: ExecuteCommand()
Posted: Tue Oct 18, 2011 10:53 am
by mags88
Hi,
Thanks for everyone's advice, this works fine now.
Re: ExecuteCommand()
Posted: Tue Oct 18, 2011 1:35 pm
by qml
mags88 wrote:Hi,
Thanks for everyone's advice, this works fine now.
As a matter of courtesy, are you able to write how you solved your problem in the end? This could help someone browsing this forum.
Re: ExecuteCommand()
Posted: Tue Oct 18, 2011 11:24 pm
by Gregor Koch
Seconded.
Bit curious what the error was.
Re: ExecuteCommand()
Posted: Fri Oct 28, 2011 9:19 am
by mags88
Sorry for the delay,
My goal was to get TI to find a file (a file that I would not know the name of) upload the data from said .csv file, once data had been uploaded into a cube, move said .csv file then loop the process so it looks for the next file in the source folder, uploads the next .csv file, moves and finds the next one (on loop until no more files found). Here is my T.I.
Code: Select all
vPrevFile = '';
vWild = WildcardFileSearch('C:\dest\*.csv', vPrevFile);
vDate = Today |'_';
vNWild = INSRT(vDate, vWild, 1);
vNFileName = INSRT('Processed_', vNWild, 1);
while (~(vWild @= ''));
#ExecuteProcess('SlaveProcess', 'filename', vWild);
vCmdRename = 'c:\dest\Batch3.bat '| vWild | ' ' | vNFileName;
ExecuteCommand(vCmdRename, 1);
vWild = WildcardFileSearch('C:\dest\*.csv', vPrevFile);
vNWild = INSRT(vDate, vWild, 1);
vNFileName = INSRT('Processed_', vNWild, 1);
End;
the slave process simply uploads the data from the found .csv file
the batch file is a simple batch file that renames the .csv file and moves it to a destination folder, by using the move command (not robocopy).