How to find if File exist and if not create it  [SOLVED]

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

How to find if File exist and if not create it

Postby arjfca » 14 Jan 2016

Hello

How can I find if a given file exist in a directory and if not, create one

G:\Users\Utilisateur\Documents\Bourse\Text_On_Chart\EUR.JPY_4_Hrs.txt

Martin

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: How to find if File exist and if not create it

Postby TJ » 14 Jan 2016

Hello

How can I find if a given file exist in a directory and if not, create one

G:\Users\Utilisateur\Documents\Bourse\Text_On_Chart\EUR.JPY_4_Hrs.txt

Martin
The PRINT command should do that for you.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: How to find if File exist and if not create it  [SOLVED]

Postby arjfca » 14 Jan 2016

Hello

How can I find if a given file exist in a directory and if not, create one

G:\Users\Utilisateur\Documents\Bourse\Text_On_Chart\EUR.JPY_4_Hrs.txt

Martin
The PRINT command should do that for you.
Print(File("C:\test.txt"),CurrentDate,CurrentTime);
File("PathFilename") - Specifies an ASCII file as the output target; if the specified file does not exist, the file will be created.

I learn something... I never new that I could do that with the print command

I will go to bed less dummy...

Martin

orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

Re: How to find if File exist and if not create it

Postby orion » 15 Jan 2016

TJ's suggestion will work. Additional note: one issue with print() is that it will truncate existing file and so if you want to avoid that and still want to know if a file already exists, use ELC.PathExists().

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: How to find if File exist and if not create it

Postby TJ » 15 Jan 2016

Also read up on

FileAppend


Return to “MultiCharts”