Writing the content of the file to .txt

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
pekus
Junior Member
Junior Member
Posts: 5
Joined: 2012-06-11, 10:57 UTC

Writing the content of the file to .txt

Post by *pekus »

Hello,

I have 1000 text files in which a sequence of digits (eg file1: 29292, file2: 48484 ...) Is the TC can save a list of text files with the content?

arthur.txt

D:\directory\file1.txt 29292
D:\directory\file2.txt 48484
...
...
...
D:\directory\plik1000.txt 74747

Thank you in advance for your tips!

Regards
Arthur
User avatar
Peter
Power Member
Power Member
Posts: 2068
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

To you know this plugin and VBS?

'*** Script for Script Content Plugin 0.2
'*** Lev Freidin (c) 2005-2008
'*** http://www.totalcmd.net/plugring/script_wdx.html

And a modification of this VBS could help:

Code: Select all

Set fso = CreateObject("Scripting.FileSystemObject") 
Set oTextStream = fso.OpenTextFile(filename) 

If not oTextStream.AtEndOfStream Then 
  s = oTextStream.ReadLine 
  Pos1 = InStr(1, s, """") 
  Pos2 = InStrRev(s, """") 
  If (Pos1 > 0) and (Pos2 > Pos1) Then 
    content = Mid(s, Pos1 + 1, Pos2 - Pos1 - 1) 
  Else 
    content = " ¦ Keinen Text mit "" in erster Zeile" 
  End If 
End If 

oTextStream.Close 
Peter
TC 10.xx / #266191
Win 10 x64
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Post by *milo1012 »

Alternative to complicated scripts:

You could use the RegXtract plugin for this.

Do these files just contain that one number each, and nothing else?
If yes, mark the files in Total Commander, open the Pack... Dialog and use the RegXtract settings:

Regular Expression:

Code: Select all

.*
Replace String:

Code: Select all

$0
[x] Line mode
(leave everything else at default setting)


Now you have an output file in the format:

[face=courier]>>>> "D:\directory\file1.txt":
>> Line 1:
29292
>>>> "D:\directory\file2.txt":
>> Line 1:
48484
...[/face]

If this format isn't satisfactory, use this file again with RegXtract, with the following settings:

Regular Expression:

Code: Select all

>>>> "(.*?)":\R>> Line \d+:\R(^.*?$)
Replace String:

Code: Select all

$1 $2
[x] Dotall
[x] Line anchors
(leave everything else at default setting)


The output file should now contain:
[face=courier]D:\directory\file1.txt 29292
D:\directory\file2.txt 48484[/face]

just as you wanted.
User avatar
Peter
Power Member
Power Member
Posts: 2068
Joined: 2003-11-13, 13:40 UTC
Location: Schweiz

Post by *Peter »

milo1012 wrote:....The output file should now contain:
....
just as you wanted.
That's impressive :D

Peter
TC 10.xx / #266191
Win 10 x64
pekus
Junior Member
Junior Member
Posts: 5
Joined: 2012-06-11, 10:57 UTC

Post by *pekus »

Big thanks for the advice / tips. Due to the late hour, tomorrow I will fight to the problem.

@Peter: Unfortunately, I do not know VBS.

Regards from Poland.
Post Reply