For AHK Gurus only (Problem with AHK script to make the same as a XY script).

Discuss and share scripts and script files...
Post Reply
Horst
Posts: 1352
Joined: 24 Jan 2021 12:27
Location: Germany

For AHK Gurus only (Problem with AHK script to make the same as a XY script).

Post by Horst »

I have an XY script which adds an ADS stream to a list of selected files.
Now I try to make an AHK script which gets a list of file names
and adds a fixed ADS stream named Tag to each file from the list.
Basically the logic works but the FileAppend function doesn't write the ADS Tag.
It works using a hard-coded FileAppend like
FileAppend, "data", full_pathname:Tag

Here is the script, which contains messages to show what's going on.
The final parameters look like there is some strange character and makes the :Tag into a new line.

Code: Select all

; Read a file list and add ADS Tag to each file

; Check if the file list parameter is provided
if (1 > 0) {
    ; Get the file name from the command line parameter
    fileListPath := A_Args[1]
} else {
    MsgBox, 0, Error, No file list name provided.
    ExitApp
}

; Check if the file list exists
if (!FileExist(fileListPath)) {
    MsgBox, 0, Error, The file list does not exist: %fileListPath%
    ExitApp
}

; Open the file for reading
FileRead, fileContents, %fileListPath%

; Split the file contents into an array of lines
fileArray := StrSplit(fileContents, "`n")

; Loop through each line in the array
Loop, % fileArray.MaxIndex()
{
    filePath := fileArray[A_Index]
    ; Remove any leading or trailing whitespace (including line breaks)
    filePath := Trim(filePath)
    
    ; Skip empty lines
    if (filePath = "")
        continue

    ; Perform an action with the file path
    MsgBox, 0, File Path, %filePath%
	
	; Define the ADS name
	ADSName = %filePath%:Tag
	ADSName := Trim(ADSName)

	; Define the data to be written to the ADS
	Data := "test1"

	; Append the data to the ADS
	MsgBox, 0, Parameters,%Data% %ADSName%
	FileAppend, %Data%, %ADSName%
    MsgBox, 0, Error level, %ErrorLevel%
}

; Exit the script after processing the list
ExitApp
  
Windows 11 Home, Version 25H2 (OS Build 26200.7462)
Portable x64 XYplorer (Actual version, including betas)
Display settings 1920 x 1080 Scale 100%
Everything 1.5.0.1404a (x64), Everything Toolbar 2.1.1, Listary Pro 6.3.6.99

highend
Posts: 14671
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: For AHK Gurus only (Problem with AHK script to make the same as a XY script).

Post by highend »

Read the file content properly: FileRead, fileContents, *t %fileListPath%
One of my scripts helped you out? Please donate via Paypal

Horst
Posts: 1352
Joined: 24 Jan 2021 12:27
Location: Germany

Re: For AHK Gurus only (Problem with AHK script to make the same as a XY script).

Post by Horst »

highend wrote: 12 Jul 2024 17:00 Read the file content properly: FileRead, fileContents, *t %fileListPath%
You are my Hero :D
Works perfect now.
Windows 11 Home, Version 25H2 (OS Build 26200.7462)
Portable x64 XYplorer (Actual version, including betas)
Display settings 1920 x 1080 Scale 100%
Everything 1.5.0.1404a (x64), Everything Toolbar 2.1.1, Listary Pro 6.3.6.99

Post Reply