Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

check if directory exists

Hi all,

is there a way to check if a directory exists? and if it doens't exist create the directory?

thanks in advance 🙂

Rey-man

1 Solution

Accepted Solutions
disqr_rm
Partner - Specialist III
Partner - Specialist III

How about this one?

if FileTime('C:\Test') > 0 then
Set vDirExists = 'Yes';
else
Set vDirExists = 'No';
end if

View solution in original post

11 Replies
Not applicable
Author

Try this:

sub createFolder

newfolder = "E:\QVApplications\QVTest\newone"
set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(newfolder) Then
Set newfolder = fso.CreateFolder(newfolder)
End If

end sub

Regards,

Gordon

Not applicable
Author

Hi Gordon,

its not working the way it want it i guess. This looks like a macro. I want it in the load script.

I fill in the tablename and description manually. Based on the name, it should create the directory. (see LET vDir)


LET vDir = 'D:\QlikView Storage\Private Data\Source Documents\Data\SAP ECC\$(vNaam)\';

SET fso = CreateObject("Scripting.FileSystemObject")
IF NOT fso.FolderExists('$(vDir)') THEN
SET newfolder = fso.CreateFolder('$(vDir)')

'$(vNaam)':
LOAD
*

;
SQL SELECT *
FROM $(vNaam)
;

//STORE $(vNaam) INTO ../Data/SAP ECC/New/$(vDesc)$(vQVD_ECC_version)$(vVersionNumber)$(vWeek)$(Year).qvd;
STORE $(vNaam) INTO $(vDir)$(vNaam)_$(vDesc)$(vQVD_ECC_version)$(vVersionNumber)$(vWeek)$(Year).qvd;
DROP TABLE $(vNaam);

End If


Hope its clear what im trying to say.

Regards,

Rey-man

Not applicable
Author

You can create the function in your macro and execute the function during the script reload

LET CreateFolder = CreateFolder();

//Where CreateFolder is the macro function

This way the macro will be launched only during reload of application

.

Rgds,

Sébastien

Not applicable
Author

Hi Sébastien,

i don't want to use a macro if its not necessary.

Is there a way to avoid this? or is it the only option?

Rgds,

Rey-man

Not applicable
Author

I don't think about another way...

disqr_rm
Partner - Specialist III
Partner - Specialist III

Here is another option for you.

Use this is your QV script:

Let vTime = FileTime('C:\Test');

In abopve line "Test" is a directory in "C" drive. If vTime is empty, directory doesn't exists. 🙂

I was surprised to see that this file function works on directories as well, atleast on my machine. Please validate if it works on your machine as well.

Not applicable
Author

Hi Rakesh,

I tested it, but of course, if the directory doesn't exists, the variable vTime neither exists.

So how can I create an if function then, cause the compiler returns an error in the script. Its says IF '' = '' then ...

Regards

Rey-man

disqr_rm
Partner - Specialist III
Partner - Specialist III

How about this one?

if FileTime('C:\Test') > 0 then
Set vDirExists = 'Yes';
else
Set vDirExists = 'No';
end if

Not applicable
Author

Now the only part remains the creation of this directory itself.

Greetz

Rey-man