It is currently April 23rd, 2024, 7:32 pm

(Modified) How to empty text file? > Specify File Path

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: (Modified) How to empty text file? > Specify File Path

Post by jsmorley »

gkmaz9 wrote: August 29th, 2019, 2:13 pm as you say, I won't depend too much on Forum.
Sometimes it will be enough to ask for help.

In fact,...The work is almost finished.
All that's left is...
1. Creating a text file with the current date and moving the logs in order

2. Making the 'bang command' work automatically

3. Arrange variables in chronological order

4. Modify Design
5. Simplify the script. I don't know if I should.

I will try the number 1, 2, 3 on my own.
If not, I'll ask for help here.

Of course, it would be nice to give a hint anytime. ;-)

Language problems are nerve-wracking.
In the Rainmeter script, I was writing using a "Codepage=".

Part of the script was written in a foreign language.
I'm a foreigner. The language was conveniently used.
I hope it don't crash in Lua. :-(
What I would do is:

Encode the skin .ini file and any .inc files you are using with @Include as UTF-16 LE.
Encode the .lua script file as UTF-16 LE.
Never use Lua to "write" to any of those files.

Encode any external text files you are using as UTF-8 W/BOM.
Use Lua to "write" to these files.
Use either Lua to read these files, or use WebParser in Rainmeter to read them.
Never "write" to these files with !WriteKeyValue in Rainmeter.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: (Modified) How to empty text file? > Specify File Path

Post by jsmorley »

I would note that there is an alternative to Lua, that isn't quite as well integrated into Rainmeter, but might be useful for managing external text files. That would be to use Window's PowerShell environment, which you can call with the !RunCommand plugin on demand. PowerShell can easily read or write any encoding format.

I'm no expert on PowerShell, so I probably won't be much help if you want to explore that, but I'm pretty sure it can be done.
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

Re: (Modified) How to empty text file? > Specify File Path

Post by gkmaz9 »

Does UTF-16 LE mean ANSI?
I used UTF-8 until yesterday, but now I have converted to ANSI.
I don't use UTF-8 anymore.
When using a Web parser, I used UTF-8 because ANSI didn't work.
Because the text file was a foreign language document, UTF-8 was an attempt to solve the problem.
Now, I solved the problem using CodePage=.
I don't use UTF-8 now, I won't use it as you say

Did I understand your advice well?
I just learned as a hobby...I am a beginner. Half of what you say is understood.
I hope I understand your advice properly.

I don't know if it's a difficult one for me to learn, but I'll consider Power Shells.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: (Modified) How to empty text file? > Specify File Path

Post by jsmorley »

gkmaz9 wrote: August 29th, 2019, 2:42 pm Does UTF-16 LE mean ANSI?
I used UTF-8 until yesterday, but now I have converted to ANSI.
I don't use UTF-8 anymore.
When using a Web parser, I used UTF-8 because ANSI didn't work.
Because the text file was a foreign language document, UTF-8 was an attempt to solve the problem.
Now, I solved the problem using CodePage=.
I don't use UTF-8 now, I won't use it as you say

Did I understand your advice well?
I just learned as a hobby...I am a beginner. Half of what you say is understood.
I hope I understand your advice properly.
No, UFT-16 LE is 16-bit Unicode with a "little endian" byte-order-mark. It is what both Windows and Rainmeter uses to read and write files natively. UTF-8 is 8-bit Unicode, with or without a byte-order-mark. UTF-8 is what the "web" uses... Both UTF-8 and UTF-16 can handle all the foreign characters and Unicode characters you are likely to need.

ANSI is an older encoding format, that is sorta "vanilla". It is intended to handle only the first 128 characters from the ASCII character set. If you put characters above 128 in ASCII, or put Unicode characters in it, that in effect makes it UTF-8 w/o BOM. I would stay away from it entirely. At best it is confusing. In the modern world, things are either UTF-8 or UTF-16 LE.

As I said above, for your purposes, I would:

Encode the skin .ini file and any .inc files you are using with @Include as UTF-16 LE.
Encode the .lua script file as UTF-16 LE.
Never use Lua to "write" to any of those files.

Encode any external text files you are using as UTF-8 W/BOM.
Use Lua to "write" to these files.
Use either Lua to read these files, or use WebParser in Rainmeter to read them.
Never "write" to these files with !WriteKeyValue in Rainmeter.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: (Modified) How to empty text file? > Specify File Path

Post by jsmorley »

If you are using Notepad in Windows, the encoding is done when you "Save as".


1.jpg
You do not have the required permissions to view the files attached to this post.
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

Re: (Modified) How to empty text file? > Specify File Path

Post by gkmaz9 »

I use a Windows notepad, and UTF-16 is not in the save fomat....in my Notepad(ANSI, UINCODE, UNICODE(BE), UTP-8)
Comparing to mine, I think that's the Unicode.
Not long ago, I thought ANSI was UTF-16.

I can see a little why the file often crashed.
Then...I'll use Unicode or Notepad++.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: (Modified) How to empty text file? > Specify File Path

Post by jsmorley »

gkmaz9 wrote: August 29th, 2019, 2:59 pm I use a Windows notepad, and UTF-16 is not in the save fomat....in my Notepad(ANSI, UINCODE, UNICODE(BE), UTP-8)
Comparing to mine, I think that's the Unicode.
Not long ago, I thought ANSI was UTF-16.

I can see a little why the file often crashed.
Then...I'll use Unicode or Notepad++.
I assume you are on Windows 7 then.

I would indeed suggest Notepad++

In that the encodings are listed as:

2.jpg

UCS-2 is what Notepad++ calls UTF-16. They are more or less the same.
You do not have the required permissions to view the files attached to this post.
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

Re: (Modified) How to empty text file? > Specify File Path

Post by gkmaz9 »

I just changed it to Unicode in NotePad, but Rainmeter doesn't recognize Korean. Sometimes Because of the language problem. I'll use a notepad ++.
Last edited by gkmaz9 on August 29th, 2019, 3:05 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: (Modified) How to empty text file? > Specify File Path

Post by jsmorley »

gkmaz9 wrote: August 29th, 2019, 3:04 pm I just changed it to Unicode, but Rainmeter doesn't recognize Korean. Sometimes Because of the language problem, I may have no choice but to use ANSI
No, you never want to use ANSI.

If this is an external file you will be reading with Lua, you must first encode the file as UTF-8 W/BOM, THEN, and only then, copy and paste in whatever text you want. Save it, and it will save the Korean just fine as UTF-8.

If this is a .ini or .inc file you will be reading with Rainmeter you must first encode the file as UTF-16 LE, THEN, and only then, copy and paste in whatever text you want. Save it, and it will save the Korean just fine as UTF-16 LE.
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

Re: (Modified) How to empty text file? > Specify File Path

Post by gkmaz9 »

The purpose of this skin is automation, and I'll find the best way To use UTF-16.