Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

datanibbler
Esteemed Contributor

Trouble executing a RENAME command using QlikView

Hi,

in my own library, I have a directory of 6.000 files - I have extracted 4 for testing - which I need to rename:

The filenames as of now are

- 0005498.01.jpg

- 0005498.02.jpg

- 0005539.01.jpg

- 0005539.02.jpg

All of them have a two-digit number associated and I need to rename them to a 9-digit number with that included =>

- 000549806.01.jpg

- 000549806.02.jpg

(that two-digit number is 06)

- 000553901.01.jpg

- 000553901.02.jpg

(that number is 01)

My code for that which, needless to say, does not yet work, is

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

FOR i = 0 TO ($(v_nr_rows)-1)
LET v_filename_old = PEEK('Dateiname_incl_Pfad', $(i), PrioListe_mit_AI_Test);
LET v_filename_new = PEEK('Dateiname_to_be_incl', $(i), PrioListe_mit_AI_Test);
EXECUTE cmd.exe /C rename $(v_filename_old) $(v_filename_new);
NEXT i

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

(where "Dateiname_incl_Pfad" is the filename as stated above with the complete pathname.

Can someone help me tell why this does not work?

As I said, i have to do this on the entire 6.400 files, but these 4 are for testing.

Thanks a lot!

Best regards,

DataNibbler

1 Solution

Accepted Solutions
datanibbler
Esteemed Contributor

Re: Trouble executing a RENAME command using QlikView

Okay,

the problem was the filepath: The RENAME command seemingly cannot work with a filename_incl_path. Instead, I have to use a DIRECTORY command before the loop and then work with only the filename_incl_ending.

That way, it works.

Thanks a lot guys!

9 Replies
MVP & Luminary
MVP & Luminary

Re: Trouble executing a RENAME command using QlikView

Hi DataNibbler,

extend the execute to a cmd-message to see if there any error:

EXECUTE cmd.exe /C rename $(v_filename_old) $(v_filename_new) >C:\output.txt;

maybe there is an error with the path - if there any spaces or special chars the statements needed to wrapped in double-quotes, this meant the variable $(v_filename_old) must then return "Path\File".

- Marcus

datanibbler
Esteemed Contributor

Re: Trouble executing a RENAME command using QlikView

Hi Marcus,

yep, that is a good idea. I will output the results to a txt file and report back here.

datanibbler
Esteemed Contributor

Re: Trouble executing a RENAME command using QlikView

Hi Marcus,

I have done that - but the system did not write anything to that txt file - so I guess the EXECUTE command did not actually do anything although I saw the cmd-line window popping up for a split-second.

Maybe I should try putting a DIRECTORY command before the loop and then use just the filenames (incl. the ending)?

Highlighted
cesaraccardi
Valued Contributor

Re: Trouble executing a RENAME command using QlikView

Hi,

I would suggest the following:

     1. Make sure the "Can execute external programs" check box is ticked

     2. Add a "TRACE" line between the LET commands and the EXECUTE command to print out the content of the variables to check they are populated correctly

     3. If #2 is ok then check if EXECUTE command is working with explicit values, test running on a cmd prompt window first (Start + R, "cmd" and press "enter") to make sure it is correct. e.g: rename 0005498.01.jpg 000549806.01.jpg;

MVP & Luminary
MVP & Luminary

Re: Trouble executing a RENAME command using QlikView

Yea, you should make a trace on $(i) and $(v_nr_rows)

datanibbler
Esteemed Contributor

Re: Trouble executing a RENAME command using QlikView

Hi Cesar,

yes, I will try that next.

I just realized I can seemingly only create folders on C:\, but no files, so I just redirected that output.txt to the "MyDocuments" directory.

I am sure that the variables are populated properly, I am watching them in the Debugger all the time.

datanibbler
Esteemed Contributor

Re: Trouble executing a RENAME command using QlikView

Now the output.txt was properly generated, but it is empty.

Next I will try executing that command directly on the command_line.

datanibbler
Esteemed Contributor

Re: Trouble executing a RENAME command using QlikView

Okay,

the problem was the filepath: The RENAME command seemingly cannot work with a filename_incl_path. Instead, I have to use a DIRECTORY command before the loop and then work with only the filename_incl_ending.

That way, it works.

Thanks a lot guys!

MVP
MVP

Re: Trouble executing a RENAME command using QlikView

Command line programs (and actually others too) that write to standard output might also use something called standard error output too.

The RENAME command actually reports errors not to the standard output but to the standard error output.

So instead of doing this:

EXECUTE cmd.exe /C rename $(v_filename_old) $(v_filename_new) >C:\output.txt;


You should be doing this:


EXECUTE cmd.exe /C rename $(v_filename_old) $(v_filename_new)  2>C:\error_output.txt;


Notice the number 2 in front of the >


This will send any error messages reported by RENAME to the error_output.txt