March 29, 2024, 05:33:18 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Saving Files

Started by TexasPete, October 24, 2009, 05:31:10 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TexasPete

October 24, 2009, 05:31:10 AM Last Edit: October 24, 2009, 05:38:36 AM by TexasPete
Converting from Lb to Cb.
I did the following example.


FILESAVE$=DDefaultDir$+"\"+"ProjectFiles"+"\" +ProjectName$+"\" +PageName$+".ckl"
def SaveFile:FILE
If (OPENFILE(SaveFile,FILESAVE$,"W")=0)
Write SaveFile, "This is a Test"
CloseFile SaveFile


Any comments of suggestions would be helpful.

Thanks Texas Pete

SnarlingSheep

Try this example:
def SaveFile:FILE
def filename:STRING

filename = "c:\CBTestWrite.txt"

if (OPENFILE(SaveFile,filename,"W")=0)
  messagebox 0,"Opened '"+filename+"' for writing.","CB Write Test"

  write SaveFile, "This is a Test"

  messagebox 0,"Wrote string to '"+filename+"'.","CB Write Test"

  closefile SaveFile

  messagebox 0,"Closed '"+filename+"'.","CB Write Test"
else
  messagebox 0,"Unable to open '"+filename+"' for writing","CB Write Test"
endif

aurelCB

Snarling i think that your example is not right answer.
Pete need first create folder then create subfolder with project name then write file in this subfolder.
How do that - I dont know....?

SnarlingSheep

My example is the basics of what Pete needs to open a file and write to it.
That is exactly what he needs to learn before jumping into converting LB code.

aurelCB

OK your example is base for write file I agree.
But do you see :
DEF FILESAVE$:STRING
DEF filter:STRING
DEF DDefaultDir$, ProjectName$,PageName$:STRING

So my question still stay - how create subfolder in folder ???

SnarlingSheep

Something like this?

def SaveFile:FILE
def filename$,DDefaultDir$,ProjectName$,PageName$:STRING
def handle:INT

DDefaultDir$ = "c:\CBTestDir"
ProjectName$ = "TestProject"
PageName$ = "TestPage"

'Set to path of directory
filename$ = DDefaultDir$+"\"+"ProjectFiles"+"\"+ProjectName$

'Check if DDefaultDir$ exists
handle = findopen(DDefaultDir$)
if (handle == 0)
  'If it doesn't exist, create it.
  if (createdir(DDefaultDir$) == 0)
    messagebox 0,"Error creating '"+DDefaultDir$+"' directory","CB WriteTest"
    findclose handle
    end
  endif
endif
findclose handle

'Check if ProjectFiles exists
handle = findopen(DDefaultDir$+"\"+"ProjectFiles")
if (handle == 0)
  'If it doesn't exist, create it.
  if (createdir(DDefaultDir$+"\"+"ProjectFiles") == 0)
    messagebox 0,"Error creating '"+DDefaultDir$+"\"+"ProjectFiles""' directory","CB WriteTest"
    findclose handle
    end
  endif
endif
findclose handle

'Check if ProjectName$ exists
handle = findopen(DDefaultDir$+"\"+"ProjectFiles"+"\"+ProjectName$)
if (handle == 0)
  'If it doesn't exist, create it.
  if (createdir(DDefaultDir$+"\"+"ProjectFiles"+"\"+ProjectName$) == 0)
    messagebox 0,"Error creating '"+DDefaultDir$+"\"+"ProjectFiles"+"\"+ProjectName$+"' directory","CB WriteTest"
    findclose handle
    end
  endif
endif
findclose handle

'Add file name to the end of the directory
filename$ = filename$+"\"+PageName$+".ckl"

if (OPENFILE(SaveFile,filename$,"W")=0)
  messagebox 0,"Opened '"+filename$+"' for writing.","CB Write Test"

  write SaveFile, "This is a Test"

  messagebox 0,"Wrote string to '"+filename$+"'.","CB Write Test"

  closefile SaveFile

  messagebox 0,"Closed '"+filename$+"'.","CB Write Test"
else
  messagebox 0,"Unable to open '"+filename$+"' for writing","CB Write Test"
endif

aurelCB

October 24, 2009, 12:25:37 PM #6 Last Edit: October 24, 2009, 12:27:36 PM by aurelCB
Yes... ;D
Oh my I completly forget command FINDOPEN ::)
This is excellent example ,thank you Snarling ;)