hello all ...
how i can print this output with tab's
Output:
ilename: reminders.db [x-sqlite3]
Filename: plus.db [x-sqlite3]
Filename: config.db [x-sqlite3]
Filename: downloads.db [x-sqlite3]
Filename: playlog.db [x-sqlite3]
Filename: google_analytics2_v4.db [x-sqlite3]
Filename: ns.db [x-sqlite3]
Filename: phenotype.db [x-sqlite3]
Filename: google_analytics_v4.db [x-sqlite3]
Filename: icing_contacts.db [x-sqlite3]
Filename: device_connections.db [x-sqlite3]
Filename: peoplelog.db [x-sqlite3]
Filename: gcm_registrar.db [x-sqlite3]
Filename: pluscontacts.db [x-sqlite3]
Filename: rmq.db [x-sqlite3]
Filename: iu.upload.db [x-sqlite3]
Filename: signal_client_Matchstick.db [x-sqlite3]
Filename: netrec [x-sqlite3]
Filename: networkstatistics.sqlite [x-sqlite3]
Filename: dg.db [x-sqlite3]
Filename: gass.db [x-sqlite3]
Filename: context_feature_default.db [x-sqlite3]
Filename: context_mahransalhi99_gmail.com.db [x-sqlite3]
Filename: fitness.db.mahransalhi99_gmail.com [x-sqlite3]
like this :
Which python code generated the output without the tabs?
(Jun-23-2019, 06:26 AM)Gribouillis Wrote: [ -> ]Which python code generated the output without the tabs?
import magic
import os
import pathlib
from colorama import Fore, Back
import colorama
colorama.init(autoreset=True)
#p = r"C:\Users\adam\Desktop"
p = r"/root/Downloads/image-mount/data/com.google.android.gms/databases"
i = 0
for dirName, subdirList, fileList in os.walk(p):
i = i + 1
print( '[+]Found Directory:#{0}\t'.format(str(i)) + "|SubDirectory:\t" + str(len(subdirList)) + " | Files:\t" +str(len(fileList))+ Fore.RED +" \t> PATH = " +Fore.RESET + dirName )
try:
for fname in fileList:
q = os.path.join(dirName, fname)
d = magic.from_file(q, mime=True)
if d == "application/x-sqlite3":
print(Fore.BLUE + ' \t Filename: {0}\t[{1}]'.format(fname,d[12:]))
#print("{}. {} appears {} times.".format(i, key, wordBank[key]))
except:
continue
You could use a third party module such as prettytable
>>> from prettytable import PrettyTable
>>> t = PrettyTable()
>>> t.add_row(['foo', 'bar'])
>>> t.add_row(['baz', 'qux'])
>>> t.add_row(['spam', 'eggs'])
>>> str(t)
'+---------+---------+\n| Field 1 | Field 2 |\n+---------+---------+\n| foo | bar |\n| baz | qux |\n| spam | eggs |\n+---------+---------+'
>>> print(t)
+---------+---------+
| Field 1 | Field 2 |
+---------+---------+
| foo | bar |
| baz | qux |
| spam | eggs |
+---------+---------+
>>> t.header = False
>>> t.align = 'l'
>>> from prettytable import NONE
>>> t.hrules = NONE
>>> t.vrules = NONE
>>> print(t)
foo bar
baz qux
spam eggs
You could use string formatting,should always use
f-string
.
import os
insert = '[x-sqlite3]'
for fn in os.scandir('.'):
print(f'{fn.name:<35}{insert}')
Output:
2019-06-13_#1.0.tws [x-sqlite3]
2019-06-13_#1.1.tws [x-sqlite3]
2019-06-13_#1.2.tws [x-sqlite3]
2019-06-13_#1.3.tws [x-sqlite3]
filename.csv [x-sqlite3]
file_reg.py [x-sqlite3]
file_test.py [x-sqlite3]
foooooooooooooooooooooo.txt [x-sqlite3]
read_test.py [x-sqlite3]
tsw_files.txt [x-sqlite3]
tws.py [x-sqlite3]
Your line 12 is not nice,could delete all
+
and
str
and use f-string
Here the start of line.
>>> i = 999
>>> subdirList = [1,2,3]
>>> print('[+]Found Directory:#{0}\t'.format(str(i)) + "|SubDirectory:\t" + str(len(subdirList)))
[+]Found Directory:#999 |SubDirectory: 3
>>>
>>> # Now the same with f-string
>>> print(f'[+]Found Directory:#{i} |SubDirectory: {len(subdirList)}')
[+]Found Directory:#999 |SubDirectory: 3
thank u all ...
snippsat : thank u man this is the simple way :) best solution <3
(Jun-23-2019, 09:00 AM)Gribouillis Wrote: [ -> ]You could use a third party module such as prettytable
>>> from prettytable import PrettyTable
>>> t = PrettyTable()
>>> t.add_row(['foo', 'bar'])
>>> t.add_row(['baz', 'qux'])
>>> t.add_row(['spam', 'eggs'])
>>> str(t)
'+---------+---------+\n| Field 1 | Field 2 |\n+---------+---------+\n| foo | bar |\n| baz | qux |\n| spam | eggs |\n+---------+---------+'
>>> print(t)
+---------+---------+
| Field 1 | Field 2 |
+---------+---------+
| foo | bar |
| baz | qux |
| spam | eggs |
+---------+---------+
>>> t.header = False
>>> t.align = 'l'
>>> from prettytable import NONE
>>> t.hrules = NONE
>>> t.vrules = NONE
>>> print(t)
foo bar
baz qux
spam eggs
when i use pretytable in my loop it's print them like this way :
Output:
[+]Found Directory:#131 |SubDirectory: 0 | Files: 4 > PATH = C:\Users\adam\Desktop\Tor Browser\Browser\TorBrowser\Tor\PluggableTransports
+-------------------------+-----------+
| Filename | FileType |
+-------------------------+-----------+
| 3561288849sdhlie.sqlite | x-sqlite3 |
+-------------------------+-----------+
+-------------------------+-----------+
| Filename | FileType |
+-------------------------+-----------+
| 3561288849sdhlie.sqlite | x-sqlite3 |
+-------------------------+-----------+
+-------------------------+-----------+
| Filename | FileType |
+-------------------------+-----------+
| 3561288849sdhlie.sqlite | x-sqlite3 |
+-------------------------+-----------+
+-------------------------+-----------+
| Filename | FileType |
+-------------------------+-----------+
| 3561288849sdhlie.sqlite | x-sqlite3 |
+-------------------------+-----------+
[+]Found Directory:#132 |SubDirectory: 0 | Files: 0 > PATH = C:\Users\adam\Desktop\Tor Browser\Browser\TorBrowser\UpdateInfo
how i can make add them to the same table ?? not table for each file