Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
datanibbler
Champion
Champion

Load pictures and save them again with a different filename

Hi,

I know it's possible to load pictures into QlikView. I'm not sure how right now since I haven't been working much with QlikView for a while now. The tool is not very much in focus these days.

Now, however, I have a task that I could very well use it for: I just need to load pictures saved with the .jpg ending - about 23.000, all with a seven-digit number as filename (like >> #######.01.jpg <<) - there are some with >> #######.02 << when the original ppt has two slides.

There is the task now to add to that seven-digit number another two digits, so the new format will be >> #########.01.jpg << - nothing else. I just have to load the files and save them again with the new name - the additional two digits aren't always the same, they have to be taken from another source, but that should not pose a problem.

I know right well that there are quite a lot of specific little tools for this task which would probably be faster because just renaming a file is logically faster than loading and saving it. The thing is that installing any kind of software in this company necessitates a rather lengthy process of checking and releasing by IT on different levels. So it would probably be easier to just do it with the tools we have. Runtime is not very critical as this will have to be done only once.

Can you tell me what would be the fastest way of doing this?

Thanks a lot!

Best regards,

DataNibbler

1 Solution

Accepted Solutions
marcus_sommer

Something like this worked as counter in for each:

let  counter = 1;

for each ...

     ...

    let  counter = $(counter) + 1;

next

- Marcus

View solution in original post

31 Replies
marcus_sommer

Hi DataNibbler,

you could use qv for this without loading those files. See here a example to create and execute a batch-file in qv which moved a file but other statements like copy or rename are also possible:

Is it possible to create a batch file in the Qlikview Script

MS-DOS ren and rename command help

- Marcus

datanibbler
Champion
Champion
Author

Hi Marcus,

that's great.

I can just make a loop over all the files in that directory, grab the first seven digits of the filename, use them to look up what the new filename should be and pass that to the batch_file. That should be the fastest way. I'm not quite sure whether I'm allowed to run a batch_file that manipulates files stored on the server, but it's worth a shot.

I'll be back here if I have any questions concerning that batch_file which is quite probable.

Thanks a lot!

Best regards,

DataNibbler

P.S.: Do I even need a separate batch file? I can use the EXECUTE command and execute a command_line from QlikView, can't I?

I remember doing that to delete some temporary files one of my scripts generated.

datanibbler
Champion
Champion
Author

Hi,

that seems to be more difficult than I thought.

The directory with the files I want to rename is on the server, on a drive labeled S:

The complete directory is

>> S:\Quality\07 Qualitätssicherung\09 Identbilder syncreon\JPEG Identphoto\Tests_FH_20160111 <<

I can rename files there, I do have RW access, and using the command_line I can rename files in whichever directory i happen to be at the moment.

I now tried

>> EXECUTE cmd \C rename "S:\Quality\07 Qualitätssicherung\09 Identbilder syncreon\JPEG Identphoto\Tests_FH_20160111\2401633.01.jpg" b.jpg <<

(this command works when I type it directly into the command_line)

But somethhing seems to be wrong - the whole thing hangs after meeting this command.

Any help with this is appreciated.

Thanks a lot!

Best regards,

Data Nibbler

P.S.: Okay, it has to be /C, not \C 😉 Now it works. So I just have to build up that command dynamically before executing it. Is that possible? Can I have sth like >> EXECUTE /C $(command) << ?

marcus_sommer

This should work:

EXECUTE /C $(command)

if the variable contained a valid statement - this meant for example that paths should be wrapped in double-quotes like:

let command = 'rename "S:\Path\FileX.jpg" "FileY.jpg"';

If something didn't worked you could the variable check with trace-statement if it looked like manually written.

- Marcus

datanibbler
Champion
Champion
Author

Hi Marcus,

I have been trying something like that. Yesterday, QlikView was always returning an "error in script line", but I will hang on. The difficulty was the quotes - I need to use double_quotes in my rename_statement since the file_´path contains blanks, so I have a mixture of single and double quotes. Always ddifficult. I will try again, though.

At least, the command works (even from QlikView, I think, don't remember too clearly) when the command is fix, so it is all right.

Thanks a lot!

Best regards,

DataNibbler

P.S.: Now I will start once again and write my own comments and try to execute a hard-coded command to rename just one of the files I have singled out for testing. When that works, I will try putting that command together as a variable and executing that.

=> That way I hope I will be able to tell you exactly what does and what does not work.

datanibbler
Champion
Champion
Author

Unbelievable!

I don't know why I was having such difficulties with this yesterday ... Well

1) Executing a fixed command in the command_line and in QlikView works fine.

2) Putting together that same command as a variable and executing that with $() works, too

=> The next step I have to try is to insert some more variables into that command_variable before executing it so I can adapt the command to every file as the loop processes.

=> The difficulty about that is that the first variable (for the old filename) has to go between the double quotes in the final command_variable ... that combination of quotes is always a real obstacle to me, so I do hope for your help and I'll try in the meantime ...

Another problem will probably be that there is always a dialog_box asking whether to allow the execution of external programs. I'll see if I can turn that off - otherwise that app can only be executed locally and will take a lot longer.

marcus_sommer

To avoid the dialog_box go to the user-properties in tab security.

- Marcus

datanibbler
Champion
Champion
Author

Hi Marcus,

I'm one step further now.

I can now make a variable for the old filename and integrate that into the final command_variable.

<=> but up to now, I just put one hard-coded filename into that first variable and the new filename was hard-coded, too

=> Now I have a table with all the filenames I find: There is a dummy_table and in every iteration of the loop, one<

     filename is added. Using a mapping_table from our database, I add the necessary two additional digits to that,
     so I have both the old and the new filename in that table.

=> Both those values have to go into the command_variable now.

P.S.: Can I use chr(147) and chr(148) to construct the double quotes around an element?

datanibbler
Champion
Champion
Author

It seems I can. So far, it seems to be working.

There is one more hurdle I just realized, but i can get over that - I cannot use a FOR EACH loop because for those values, I need the PEEK function and for that I need a counter - so I have to somehow count how many files are in that directory (or just look in the file_Explorer and hard-code it there as it is a one-time-app) and use a FOR loop.