Write to a file

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
11 posts • Page 1 of 2
MrKintaro
Posts:53
Joined: Fri Aug 16, 2013 6:56 pm

Write to a file

Post by MrKintaro »

hi,

can someone explain me how to open a file and add at the beginning of the file a string without overwrite what there is in the file?

Code: Select all

main()
{
  int i, tell;
  string path;
  
  file f; // our file
  int err; // error code  

  dyn_float value;
value[1]=12.123;
value[2]=8.0;
value[3]=3.1;
  
  
  path = getPath(SCRIPTS_REL_PATH);
  DebugN(path);
  //dyn_string s=getFileNames(path, "*",FILTER_DIRS);
  dyn_string s=getFileNames(path, "SetDescription.ctl",FILTER_FILES);

  for(i=1; i

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: Write to a file

Post by mkoller »

you can't INSERT something into a file.
What you have to do in this case is to:
1) write the new content into a new file
2) read the whole old content and append it to the new file
3) remove the old file
4) rename the new to the old file

MrKintaro
Posts:53
Joined: Fri Aug 16, 2013 6:56 pm

Re: Write to a file

Post by MrKintaro »

Hi Martin,

fileToString maybe an option.

do you know the limit of fileToString?

how big can be the string where I write the file?

MrKintaro
Posts:53
Joined: Fri Aug 16, 2013 6:56 pm

Re: Write to a file

Post by MrKintaro »

My point is becase I am searching a way how to encrypt the full Project but I have to insert the key in every file.

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: Write to a file

Post by mkoller »

The limit is RAM

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: Write to a file

Post by leoknipp »

Denis Pregnolato wrote:
My point is becase I am searching a way how to encrypt the full Project but I have to insert the key in every file.
Can you please describe which part of the project you want to encrypt.
Encrypting the full project is not possible by adding information to files, e.g. the database files cannot be modified by adding some text.

Best Regards
Leopold Knipp
Senior Support Specialist

MrKintaro
Posts:53
Joined: Fri Aug 16, 2013 6:56 pm

Re: Write to a file

Post by MrKintaro »

It seems very easy task but I am getting some trouble.

I want to encrypt our library that has a deep structure:

I have to loop through all the script in all folder and subfolder, but I am not finding a way to do it recursively and add the string // $License: NOLICENSE.

it seems a stupid function but I not able to loop tought the structure in a easy way.

To add the string I found the function.

RudiKreiner
Posts:198
Joined: Mon May 16, 2011 2:10 pm

Re: Write to a file

Post by RudiKreiner »

Have a look at the functions getFileNames() and isfile() in WinCC Help.
If you use getFileNames() recursively on all directories found you should easily be able to work you way through your whole file structure.

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: Write to a file

Post by leoknipp »

I've written a function which creates a list of panel files (including all sub folders) for a given path.

The code for the function I have copied to the posting, the result is written to the global variable ds_panelFilesRecursive:

dyn_string ds_panelFilesRecursive;

getFiles(string s_path)
{
dyn_string ds_panelFiles;
int i;

DebugTN(__LINE__,"call getFileNames",s_path);
ds_panelFiles = getFileNames(s_path,"*",FILTER_FILES | FILTER_DIRS);
DebugTN(__LINE__,"result of getFileNames",ds_panelFiles);

for(i=1;i

Gertjan van Schijndel
Posts:634
Joined: Mon Aug 02, 2010 10:37 am

Re: Write to a file

Post by Gertjan van Schijndel »

Just use the function 'getYoungerFiles' with as 'startTime' the value 0.

11 posts • Page 1 of 2