You are not logged in.
Pages: 1
1) How can i count all files to do "For I = 0 To FilesCount"
2) How can i wrote all new names into an array?
for FileWriteContent(C:\Test.txt, myArray)
or Export To Clipboard
3) or how can i wrote an loop to export all files each after each with FileWriteContent(C:\Test.txt,FileName) ?
- Maybe an new function FileAppendContent(C:\Test.txt, BaseName) could help ?
Psuedo Code I tried
var
ExtApp: Cardinal;
Parts, Files: TStringsArray;
BaseName: String;
var I: Integer;
begin
BaseName := WideExtractBaseName(FileName)
begin
// export
//I := I + 1;
//Files := WideScanDirForFiles('.');
//For I = 0 To Files Do
If FileName <> '' Then
Files := Files + BaseName + #13#10;
end
//FileWriteContent(const FileName: WideString; const Content: string);
FileWriteContent('c:\rentest.txt',Files);
////////////////////////////////////////////////////////////////////////
// process
//ExecuteProgram(const Command: string; WaitForProgram: Boolean): Cardinal;
ExtApp := ExecuteProgram('c:\T\0\PSPad\PSPad.exe c:\rentest.txt', false);
////////////////////////////////////////////////////////////////////////
// import
// Sleep(Milliseconds: Cardinal);
// I := I + 1;
// FileName := FileReadLine('C:\rentest.txt', I);
end.
Last edited by Stefan (2007-11-07 21:27)
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
1) How can i count all files to do "For I = 0 To FilesCount"
You can't unfortunately, because script is running for every file independently, and there is no way to know how many files there are in the list.
2) How can i wrote all new names into an array?
Answer is the same as for the previous point. You would have to go 2 passes, with 2 scripts. On the first pass, 1-st scrip will write all new names into the file. On the second pass, 2-nd script can read that file and it will have all new names available to it (including the total amount of files).
Maybe an new function FileAppendContent(C:\Test.txt, BaseName) could help ?
I've added new FileAppendContent() function, download the latest dev version:
>> procedure FileAppendContent(const FileName: WideString; const Content: string);
Offline
I've added new FileAppendContent() function, download the latest dev version:
>> procedure FileAppendContent(const FileName: WideString; const Content: string);
Maaaany thanks!
First test works with one pass only.
Have to test more after work
Minor issue:
For const FileName: WideString; an var or const is not expanded.
i.e.
Works: ExtApp := ExecuteProgram('D:\PSPad\PSPad.exe c:\rentest.txt', false);
Don't work: ExtApp := ExecuteProgram('D:\PSPad\PSPad.exe TempFile', false); (opens a new file named 'TempFile')
Example code which works so far:
const
TempFile = 'c:\rentest.txt';
var
ExtApp: Cardinal;
BaseName: String;
I, Count: Integer;
begin
If count < 1 Then
//WideDeleteFile(const FileName: WideString): Boolean;
WideDeleteFile(TempFile);
Count := 1
BaseName := WideExtractBaseName(FileName);
//FileAppendContent(const FileName: WideString; const Content: string);
FileAppendContent(TempFile, FileName + #13#10);
////////////////////////////////////////////////////////////////////////
// process
//ExecuteProgram(const Command: string; WaitForProgram: Boolean): Cardinal;
ExtApp := ExecuteProgram('D:\PSPad\PSPad.exe c:\rentest.txt', false);
// ExtApp := ExecuteProgram('D:\PSPad\PSPad.exe TempFile', false);
////////////////////////////////////////////////////////////////////////
// import - still to test
// I := I + 1;
// FileName := FileReadLine('C:\rentest.txt', I);
end.
Thank you for all your help!
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
The command which you pass to ExecuteProgram() function is passed to Windows API for the execution. So it is expanded in a standard Windows way. There just might be some confusion for the "current working directory", which breaks the connection with your file. By the word "confusion" I mean that Windows uses different working directory from which you think it is using.
Offline
The command which you pass to ExecuteProgram() function is passed to Windows API for the execution.
So it is expanded in a standard Windows way.
In an PascalScript you expand VARs and CONST every time.
So i guess you should expand the VAR in ExecuteProgram() function on your own first
and pass then the function command with the expanded VAR to the windows API.
Like you do with all other function too? Well, not to WinAPI, but inside the script. I am confused.
Maybe you need an "trigger" to detect VARs and CONST within the function? like we could use %VAR% or like that
ExtApp := ExecuteProgram('D:\PSPad\PSPad.exe %TempFile%', false);
or even
ExtApp := ExecuteProgram('%AppToExecute% %TempFile%', false);
.
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
In not sure what level of knowledge you have in Pascal language, but VAR and CONST are compiler keywords which identify how parameters are passed to the function. Both VAR and CONST mean that parameters are passed by reference, but VAR means that the variable ban be changed by the function, and CONST means that the variable passed to the function will not be changed. It is more of a safety feature of this programming language in the quest of hiding usage of pointers.
Anyway, it is a bad idea expanding filename parameters on my side, because when user passes a command to that function, normally, he/she would expect it to be executed AS IT IS, i.e. exactly as it was passed. Also, it is much easier/safer to expand these paths on client side, as you know exactly what has to be expanded.
I would recommend the usage of these two functions:
function WideExpandFileName(const FileName: WideString): WideString;
function WideGetEnvironmentVar(const VarName: WideString): WideString;
Offline
Pages: 1