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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
hopkinsc
Partner - Specialist III
Partner - Specialist III

check if DIR exists

hi all,

is there a way i can check if a directory exists, if it doesn't then create it?

I would like this done in the script

Labels (1)
3 Replies
german_avanzato
Creator
Creator

Hi,

En the script, you can use

//verify existence of a directory.

if  (FileTime('PATH') > 0 ) then

//exist

else

//if not exist.

EXECUTE cmd.exe /c mkdir PATH

endif

This will use the CMD of windows, so you will need the proper permission to the application to this work

hopkinsc
Partner - Specialist III
Partner - Specialist III
Author

Hi, thanks. would that make it dynamic though?

currently i have a loop in my script which reads DBF files from multiple directories.

so when QV reads the 1st dir and reads in each DBF i want it to check that there is a folder named 'Processed'. i then want to move the DBF's into the processed folder.

but obviously i can't hardcode a directory into the CMD.

Does that make sense?

german_avanzato
Creator
Creator

You can make it dinamic.

You could do something like this:

//Load a Table with the path you want to ceck. This could be done from a .xlxs ,etc

DIRECTORYS:

LOAD * INLINE [

    Dirs

    dir1

    dir2

    dir3

];

let vNroDir= NoOfRows('DIRECTORYS');

for i = 0 to $(vNroDir) - 1

let vDir = Peek('Dirs',$(i),'DIRECTORYS');

if  (FileTime('$(vDir)') > 0 ) then

//exist

else

//if not exist.

EXECUTE cmd.exe /c mkdir $(vDir)

endif

next i