Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
datanibbler
Champion
Champion

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
Champion
Champion
Author

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!

View solution in original post

9 Replies
marcus_sommer

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
Champion
Champion
Author

Hi Marcus,

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

datanibbler
Champion
Champion
Author

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)?

cesaraccardi
Specialist
Specialist

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;

marcus_sommer

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

datanibbler
Champion
Champion
Author

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
Champion
Champion
Author

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

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

datanibbler
Champion
Champion
Author

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!

petter
Partner - Champion III
Partner - Champion III

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