rename file script in sap bods

Hi Experts,

I have fail name “Murali06062017” . I need to rename file name like “Ready_Murali06062017” in bods using rename command script.

I have have multiple files in a path.

  1. Murali06062017
  2. Krishna06062017 in D:\Temp folder

I need to rename files in same path D:\Temp Folder

  1. Ready_Murali06062017
  2. Ready_Krishna06062017

For this I tried this way. But it was not worked

exe(‘cmd’,‘rename D:\Temp*.txt D:\Temp\Ready_*.txt’)

Please get me help on this. I google it but could not able to find proper solution.

Thanks and Regards,
Venki


ursfriend77 (BOB member since 2011-03-02)

Specify the third parameter for the EXEC function as 8 so you get the actual error.

I think I usually use “/C …” in the second parameter.


eganjp :us: (BOB member since 2007-09-12)

Hi Jim,

I have been implement what you suggested i am getting below error message

1: The syntax of the command is incorrect.

when i try to using windows command
D:\TEMP> rename .txt Ready_.txt

files are renaming like below
Ready_i06062017
Ready_a06062017
but I need Ready_Murali06062017 and Ready_Krishna06062017

please advise me how to achieve this.

Thanks
Venki


ursfriend77 (BOB member since 2011-03-02)

Try this instead:

exe(‘cmd’,’"/C rename D:\Temp\.txt D:\Temp\Ready_.txt"’, 8);

Any time you use a backslash in a string you need to escape it with another backslash.


eganjp :us: (BOB member since 2007-09-12)

Hi Jim,

I tired what you advised but no luck it is not working

exec(‘cmd’,’"/C rename D:\TEMP\.txt D:\TEMP\Ready_.txt"’,8);

I am getting error

1:’/C’ is not recognized as in internal or external command

Thanks
Venki


ursfriend77 (BOB member since 2011-03-02)

Try it without the /C then.

exec(‘cmd’,’“rename D:\TEMP\.txt D:\TEMP\Ready_.txt”’, 8 );


eganjp :us: (BOB member since 2007-09-12)

Hi Jim,

When i try with with out /C. Job is executing successfully but I did get proper result

exec(‘cmd’,‘“rename D:\TEMP\.txt D:\TEMP\Ready_.txt”’,8);

When i try to adding print function

print(exec(‘cmd’,‘“rename D:\TEMP\.txt D:\TEMP\Ready_.txt”’,8));

I am getting below error

12.2) 06-07-17 13:31:47 (2212:5148) PRINTFN: 1: The syntax of the command is incorrect.

please tell me is any other way to achieve this,

:hb: :hb:

Regards,
Venki


ursfriend77 (BOB member since 2011-03-02)

Direct the output into a local variable and then print the contents of the local variable.

The print() of the exec() should work. You need to figure out what you’re doing wrong.


eganjp :us: (BOB member since 2007-09-12)

how to call this DOS command in bods script

D:\TMP>for %a in (*.txt) do ren “%~a” “Ready_%~na%~xa”

Thanks,
Venki


ursfriend77 (BOB member since 2011-03-02)

Put it in a DOS batch file and then call the batch file from DS. In that case you may have to use the /C syntax in the second parameter of the exec() function.


eganjp :us: (BOB member since 2007-09-12)

Hi Jim,

The batch file script not working in bods

Anyone, Could you please provide the solution how to rename files with prefix the name “Ready_”. I really appreciate if any one help. I have been struggling for past 6 days on this issue.

When I apply below script in dos command it works fine, but same thing if i want to implement in bods. It is not working

for %a in (.) do ren “%a” “Ready_%a” – working through DOS command

I saved this into bat file and call those bat file in bods like below

$G_FILE_NAME = ‘D:\ETL_Data\rename\’;

$G_FILE_NAME = exec( ‘batchfile.bat’,’ ',8);

but this script is not working, please guide me how to call those windows dos command in bods

Thanks and Regards,
Venki


ursfriend77 (BOB member since 2011-03-02)

Have you searched the forum? There are plenty of examples here of how to run a .bat file from the exec() function.


eganjp :us: (BOB member since 2007-09-12)