PDA

View Full Version : Save from input to cfg, bat etc..


abnrange
06-13-2009, 04:18 PM
Hello all,

I would like to have a few button that will save all the text from an input object and save with diffrent extension such as, bat, cfg & inf. The code below is what I'm currently using and works. I want to elimate the file browse and just save with the correct extension.

I have a drop down that populates 5 files with different extensions. I have 5 buttons that are hidden and show when the current text is populated. How can I change this code to save as the right extension with out the file browse. Hope this makes sense - Thanks

-- Prompt the user for a location to save to
sSaveFileName = Dialog.FileBrowse(false, "Save", "C:\\ZFDAGENT", "bat (.bat)|.bat|", "zfd.bat", "bat", false, false)[1];

-- Get the paragraph properties
tProperties = Input.GetProperties("Input1");

-- Get the currently displayed text
sText = tProperties.Text

-- Output the text to a file
TextFile.WriteFromString(sSaveFileName, sText, false);

longedge
06-14-2009, 04:04 AM
I might not have understood correctly but it sounds like you have already got a file name and you are using a combo box to select a filename extension which you want to concatenate into the complete filename, in which case something like -

sel = ComboBox.GetSelected("ComboBox1");
ext = ComboBox.GetItemText("ComboBox1", sel);
-- or ComboBox.GetItemData if appropriate
stext = "existing file name"
sSaveFileName = stext..ext

abnrange
06-14-2009, 01:19 PM
I have attached project.

I have some files (bat, cfg, txt & inf) that get copied to local pc. I want the end user to be able to edit these files and be able to click save and it save the data from the input object to the correct location on local PC with out prompting for a location to save to. Hope that makes better sense! thanks

longedge
06-14-2009, 03:15 PM
I want the end user to be able to edit these files and be able to click save and it save the data from the input object to the correct location on local PC with out prompting for a location to save to.

Is the correct location always the same? Is it C:/ZFDAGENT in which case you need to add some code in to check if it exists and create it if not.

abnrange
06-14-2009, 03:20 PM
The files are in different locations on c:\. The only solution I could come up with was to have several save buttons each having the dialog browse which I would like to elimate. The below code works for txt files but not cfg, bat inf etc. Is there away to make the below code work? Thanks

TextFile.WriteFromString("c:\\ZFDAGENT\ZFD.bat", new_contents, false);
result = Dialog.Message("Notice", "File Saved!", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

mwreyf1
06-14-2009, 05:18 PM
The more I read this thread the more lost I become. :huh

longedge
06-14-2009, 05:57 PM
I'm afraid I'm lost too :) - why not just rename the file?

abnrange
06-14-2009, 06:11 PM
Sorry for all the confusion. What I would like to do is allow the end user to load a bat, cfg txt and inf files in to an iput object. The files are in different location on c:. Then, the end user can modify the files and just click a save button and the file is saved back in the orginal location with the correct extension. Thanks

abnrange
06-14-2009, 06:16 PM
I finally figured it! Thanks

---- The string to save
new_contents = Input.GetText("Input1");

-- Write out the modified contents of the text file.
TextFile.WriteFromString("c:\\zfdagent\\zfd.bat", new_contents, false);
result = Dialog.Message("Notice", "File Saved!", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);