Jump to content

How manage this txt file


Recommended Posts

Hi guys ,

I need you help with regex and TXT file manipulation

The question is this

I need to change HDD on several units , and new hdd could have different size but must have same structure , so i want manage previous diskpart script file to perform this operation

let's me explain , this is a tipical txt file

create partition primary size=400 ------------------------> Constant value 1

create partition EFI size=300-----------------------------> Constant value 2

create partition MSR size=128-----------------------------> Constant value 3

create partition primary size=xxxxx ---------------------> Variable value

exit

Now I want if possible

calculate the new hdd size -> OK DONE

put constant values on different variables

subtract all constant values from new hdd size and put the difference on variable position ( Variable value ) inside txt file

Can you help me with this regex manipulation ...sorry but I'mno skilled about regex

Thanks in advance for your help :sweating:

AnyB.

Edited by anybastard
Link to comment
Share on other sites

Nice, i didn't know there were diskpart scripts, anyway,

i don't see why you would need regex to do what you describe...

you seem to need more mathematics than anything else.

search for "create partition primary size=400"

isolate the numbers to the right of '='

use that number to Calculate hdd size

assign difference to a variable

write the variable to the file either by line

or the whole file with all variables in the middle

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Hi Careca ,

first for all thanks for your reply .

and yes you are right at the end is only mathematic step but my main problem is how "grab" constant values and how put the variable number on correct position

Can you make an example ...if possible ?

Thanks again

AnyB,

Link to comment
Share on other sites

You can use _FileReadToArray, and loop through the array for key words (StringInStr), then parse out everything right of the '=' (StringInStr, StringRight...or StringSplit).

Or, you can use FileRead, and use StringRegExp on the string to find what you need.

Try it out, post some code, we'll help debug.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

  • Moderators

While I am generally a fan of leading the horse to water, I think this one will die of thirst first... Try this, anybastard:

#include <Array.au3>
#include <File.au3>

Local $aArray
 _FileReadToArray(@DesktopDir & "\LazyGuysTextFile.txt", $aArray) ;Read LazyGuysTextFile.txt to an array

For $i = 1 To $aArray[0]
 If StringInStr($aArray[$i], "create partition ") Then ;search Array for the words "create partition"
   Select
    Case StringInStr($aArray[$i], "primary size=")
     $primarySize = StringRight($aArray[$i], 3)
    Case StringInStr($aArray[$i], "EFI size=")
     $EFISize = StringRight($aArray[$i], 3)
    Case StringInStr($aArray[$i], "MSR size=")
     $MSRSize = StringRight($aArray[$i], 3)
   EndSelect
 EndIf

 If StringInStr($aArray[$i], "shrink minimum") Then $shrinkMinimum = StringRight($aArray[$i], 4) ;search the array for the words "shrink minimum"

Next

 MsgBox(0, "", "Primary Size: " & $primarySize & @CRLF & "EFI Size: " & $EFISize & @CRLF & "MSR Size: " & $MSRSize & @CRLF & "Shring Minimum: " & _
 $shrinkMinimum)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hi JLogan3o13

your file is OK for my purpose ( thanks for that ) , I would ask only a little and last help

If StringInStr($aArray[$i], "create partition ") Then ;search Array for the words "create partition"
Select
Case StringInStr($aArray[$i], "primary size=")
$primarySize = StringRight($aArray[$i], 3)

Unofrtunatly constant value 1 and variable value have same name so this portion the script save inside $primarySize only 1 of 2 .

Is there a way to save both ?

Thanks again .

BRs

An1B

Link to comment
Share on other sites

anybastard,

Is this going to be part of a loop, or is the file larger? I'ts doubtful that you are writting a program for something you can do in your head, or happens infrequently.

I'm asking because it makes a difference to the solutions.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Hello .

the first one it is a part of a loop all the tool function is

- Calculate new storage size -> done

- Grab all data ( constant ) from old txt -> In progress

- recalculate a new storage size -> no problem for this part

- write a new value on old txt file -> no problem for this part

as you can see my issue is/was how grab all data

That's it

BRs

An1B

Link to comment
Share on other sites

Opening a file example:

$pfile = (@ScriptDir & 'lalalala.txt')
FileOpen($pfile, 0)
$Read = FileRead($pfile)

Posts above have pointed out the direction to go, where did you got stuck?

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Hi guys ,

as you understand I use autoit very rarely .....

OK I don't know if this is elegant way or correct way but seem work fine

I made a "preliminary " script to change/modify constant value1 row from size=400 to size1=400

and used JLogan3o13 code in order to have all data necessary ready to use for the next step

Link to comment
Share on other sites

Come back when you get stuck, and then, let us know what you have so far.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Hello guys ,

always me ... I have again a little problem related to "my" script

The problem is on this line

shrink minimum=8704-----------------------------> Constant value 3

this part of the code is ok

If StringInStr($aArray[$i], "shrink minimum:") Then $shrinkMinimum = StringRight($aArray[$i], 4) ;search the array for the words "shrink minimum"

I will have shrink minimum: 8704 . This mean that inside specific variable i have correct numeric value for next step .

The problem is that this number could be 4 or 5 characters . I mean that on different txt file I could have shrink minimum value 23456

But if i change "StringRight($aArray[$i], 4" and put 5 instead of 4 when I will have on my txt file the value with 4 characters i will have my variable with this value =8704 and this is not ok for my next step

Can you help me to solve this question , please ?

BRs

AnyB

Edited by anybastard
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...