使我的代码简单快速 [英] make my code simple and fast

查看:90
本文介绍了使我的代码简单快速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



最后我的代码正常工作。



需要3行最后一行分为两部分,后面的部分是;然后是一个15个文件的最后一行。我感兴趣的是。

然后我将所有行连接到文本文件中的一行,带有;作为值分隔字符,之后全部替换为点。



现在我有我可以使用的文件。



此文件:

Hi guys,

finaly i got my code working.

it takes the 3 line and last line from a 15 file's in a dir.
the last line is split in two parts, the part after the ; i am interested in.
then i join all the line's to one line in a textfile with a ; as value separation character, after that all , are replaced for a dot.

now i have the file i can use.

this file:

W
-10496
mnuPowerIn


63581203668;210,34
63581203728;203,46
63581203788;204,65



和这个文件




and this file

W
-10496
mnuPower


63581203668;166,81
63581203728;165,45
63581203788;164,64





和mo这些文件的转换如下:





and more of these files are converted in this:

Inverter #2 - mnuCurrent;0.83;Inverter #2 - mnuTodayEnergy;447.00;mnuPower;164.64;Inverter #2 - mnuPower;153.78;mnuPowerIn;204.65;Inverter #2 - PV1 - mnuCurrent;0.65;Inverter #2 - PV1 - mnuPower;193.28;Inverter #2 - PV1 - mnuVoltage;292.86;Inverter #2 - PV2 - mnuCurrent;1.83;Inverter #2 - PV2 - mnuPower;0.30;Inverter #2 - PV2 - mnuVoltage;0.24;Inverter #2 - lblTempTINT;38.22;mnuTodayEnergy;447.00;Inverter #2 - lblTempTI;41.26;Inverter #2 - mnuVoltage;223.85;Inverter #2 - lblGenFreqT;0.00





做得那么好。

必须运行的电脑脚本不是很快。

有人可以告诉我谁能让代码减少处理器耗时吗?

我也想摆脱额外的输出文件。

是否有办法完成所有这些并且只有一个输出文件?



这是代码:





do far so good.
The computer who has to run the script is not very fast.
can some one tell me who to make the code less processor time hungry ?
Also i want to get rid of the extra outputfiles.
is there a way to do all of this and have only one output file ?

this is the code:

$input_path = ‘e:\a\*.tmp’
$fileDirectory = ‘e:\a’
$output_file = ‘e:\b\output.txt’

Clear-Content $output_file
Clear-Content e:\b\output1.txt
Clear-Content e:\b\output2.txt

foreach($file in Get-ChildItem $fileDirectory )

{
$filePath = $fileDirectory + "\" + $file;
$A=(get-content $filePath -totalcount 3)[-1]
$B=get-content $filePath -tail 1  
Add-Content $output_file $A 
$parts = $B.split(";")
Add-Content $output_file $parts[1]
}

$c=(Get-Content $output_file) -Join ";"
Add-Content e:\b\output1.txt $c

(get-content e:\b\output1.txt) -replace ',',"." | Add-content e:\b\output2.txt









感谢高级





thanks in advanced

推荐答案

input_path ='e:\\\\ * .tmp'
input_path = ‘e:\a\*.tmp’


fileDirectory =' e:\ a'
fileDirectory = ‘e:\a’


output_file ='e:\ b\output.txt'

清除内容
output_file = ‘e:\b\output.txt’ Clear-Content


这篇关于使我的代码简单快速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆