DOMANDA Aggiungere righe di testo tramite batch

mauriziorobbiati

Utente Attivo
207
6
CPU
AMD Athlon 64 X2 4000+
Scheda Madre
Asus M2N-X
HDD
Maxtor 250 GB
RAM
Kingston 2x1 GB DDR2 667 MHz
GPU
Asus GeForce 210
Audio
C-Media 8738-LX
Monitor
Acer AL1916
PSU
Startech 500 W
Case
Cooler Master Elite 333
OS
Windows 7 Home Premium 32-bit
Ciao a tutti :D
Siccome molto spesso devo aggiornare un file .ini con delle righe che ho scritto io, mi sono chiesto se è possibile compilare un file batch che mi aggiunga automaticamente alla fine del file le seguenti righe:

[Microsoft Excel*]
LangSecRef=3024
DetectFile=%UserProfile%
Default=True
FileKey1=%UserProfile%\Application Data|*.*|REMOVESELF


[Spotify Cache*]
LangSecRef=3023
DetectFile=%LocalAppData%\Spotify
Default=True
FileKey1=%LocalAppData%\Spotify\Storage|*.*|RECURSE
FileKey2=%LocalAppData%\Spotify\Browser|*.*|RECURSE
FileKey3=%LocalAppData%\Spotify\Data|*.*|REMOVESELF


[Spotify Update*]
LangSecRef=3023
DetectFile=%LocalAppData%\Spotify\
Default=True
FileKey1=%LocalAppData%\Spotify\Update|*.*|REMOVESELF
 

Giacky91

Utente Attivo
793
84
CPU
Intel Core I7 - 2630QM - 2.0 GHZ
Scheda Madre
Proprietaria
HDD
500GB WD 2.5"
RAM
2 x 2GB Corsair
GPU
GeForce GT540M 1GB
Audio
Integrato
OS
Windows 10 Pro, Kali Linux 2.0
Ciao a tutti
biggrin.gif

Siccome molto spesso devo aggiornare un file .ini con delle righe che ho scritto io, mi sono chiesto se è possibile compilare un file batch che mi aggiunga automaticamente alla fine del file le seguenti righe:

[Microsoft Excel*]
LangSecRef=3024
DetectFile=%UserProfile%
Default=True
FileKey1=%UserProfile%\Application Data|*.*|REMOVESELF


[Spotify Cache*]
LangSecRef=3023
DetectFile=%LocalAppData%\Spotify
Default=True
FileKey1=%LocalAppData%\Spotify\Storage|*.*|RECURSE
FileKey2=%LocalAppData%\Spotify\Browser|*.*|RECURSE
FileKey3=%LocalAppData%\Spotify\Data|*.*|REMOVESELF


[Spotify Update*]
LangSecRef=3023
DetectFile=%LocalAppData%\Spotify\
Default=True
FileKey1=%LocalAppData%\Spotify\Update|*.*|REMOVESELF



ma devi aggiungere quel testo sempre allo stesso file .ini?
puoi usare il comando
Codice:
 @[URL="http://www.tomshw.it/forum/members/echo-5197.html"]echo[/URL]
per scrivere del testo a un file in batch
per esempio:
Codice:
 @[URL="http://www.tomshw.it/forum/members/echo-5197.html"]echo[/URL] This is a test > test.txt 
 @[URL="http://www.tomshw.it/forum/members/echo-5197.html"]echo[/URL] This is a test >> test.txt
la prima riga, usando un solo '>' sovrascrive il file test.txt se presente
con la seconda, usando '>>' viene aggiunta una nuova riga al file
 
Ultima modifica:

mauriziorobbiati

Utente Attivo
207
6
CPU
AMD Athlon 64 X2 4000+
Scheda Madre
Asus M2N-X
HDD
Maxtor 250 GB
RAM
Kingston 2x1 GB DDR2 667 MHz
GPU
Asus GeForce 210
Audio
C-Media 8738-LX
Monitor
Acer AL1916
PSU
Startech 500 W
Case
Cooler Master Elite 333
OS
Windows 7 Home Premium 32-bit
ma devi aggiungere quel testo sempre allo stesso file .ini?
puoi usare il comando
[CODE @echo[/CODE]
per scrivere del testo a un file in batch
per esempio:
Codice:
 @[URL="http://www.tomshw.it/forum/members/echo-5197.html"]echo[/URL] This is a test > test.txt 
 @[URL="http://www.tomshw.it/forum/members/echo-5197.html"]echo[/URL] This is a test >> test.txt
la prima riga, usando un solo '>' sovrascrive il file test.txt se presente
con la seconda, usando '>>' viene aggiunta una nuova riga al file
Mi scrive solo le prime 5 righe. Comunque, si, devo aggiungere tutto allo stesso file .ini
 

Giacky91

Utente Attivo
793
84
CPU
Intel Core I7 - 2630QM - 2.0 GHZ
Scheda Madre
Proprietaria
HDD
500GB WD 2.5"
RAM
2 x 2GB Corsair
GPU
GeForce GT540M 1GB
Audio
Integrato
OS
Windows 10 Pro, Kali Linux 2.0
Mi scrive solo le prime 5 righe. Comunque, si, devo aggiungere tutto allo stesso file .ini

ammetto di non aver testato @echo con quello che vuoi scrivere.
Ci sono alcune accortezze da prendere. Alcuni caratteri vanno "parsati". Cioé bisogna far capire a @echo che li vuoi stampare e non interpretare.
nel tuo caso ci sono due caratteri in particolare: "|" e "%"
per "|" devi anteporre il carattere "^", ad esempio se vuoi scrivere |*.*| ti basta scrivere ^|*.*^|
per "%" basta raddoppiare il carattere: DetectFile=%UserProfile% diventa DetectFile=%%UserProfile%%

non so se le righe vuote sono essenziali, nel caso le puoi scrivere su file cosi: @echo: >> file.txt
 

mauriziorobbiati

Utente Attivo
207
6
CPU
AMD Athlon 64 X2 4000+
Scheda Madre
Asus M2N-X
HDD
Maxtor 250 GB
RAM
Kingston 2x1 GB DDR2 667 MHz
GPU
Asus GeForce 210
Audio
C-Media 8738-LX
Monitor
Acer AL1916
PSU
Startech 500 W
Case
Cooler Master Elite 333
OS
Windows 7 Home Premium 32-bit
ammetto di non aver testato @echo con quello che vuoi scrivere.
Ci sono alcune accortezze da prendere. Alcuni caratteri vanno "parsati". Cioé bisogna far capire a @echo che li vuoi stampare e non interpretare.
nel tuo caso ci sono due caratteri in particolare: "|" e "%"
per "|" devi anteporre il carattere "^", ad esempio se vuoi scrivere |*.*| ti basta scrivere ^|*.*^|
per "%" basta raddoppiare il carattere: DetectFile=%UserProfile% diventa DetectFile=%%UserProfile%%

non so se le righe vuote sono essenziali, nel caso le puoi scrivere su file cosi: @echo: >> file.txt
Grazie mille ora funziona :D
 

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!

Discussioni Simili