Cómo crear un archivo de texto vacío a partir de un archivo por lotes?
¿Puede alguien recordar cuál fue el comando para crear un archivo vacío en MSDOS usando BAT file?
11 answers
echo. 2>EmptyFile.txt
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2008-10-16 20:39:25
copy NUL EmptyFile.txt
DOS tiene unos pocos archivos especiales (dispositivos, en realidad) que existen en cada directorio, NUL
siendo el equivalente del /dev/null
de UNIX: es un archivo mágico que siempre está vacío y tira todo lo que escribes en él. Aquí hay una lista de algunos otros; CON
también es ocasionalmente útil.
Para evitar tener ninguna salida, puede usar
copy /y NUL EmptyFile.txt >NUL
/y
evita que copy
haga una pregunta que no puede ver cuando la salida va a NUL
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2008-10-17 17:31:04
type NUL > EmptyFile.txt
Después de leer los dos posts anteriores, esta mezcla de los dos es lo que se me ocurrió. Parece un poco más limpio. No hay necesidad de preocuparse por redirigir el archivo " 1(s) copiado (s)."mensaje a NUL
, como lo hace el post anterior, y se ve bien al lado del ECHO OutputLineFromLoop >> Emptyfile.txt
que generalmente seguirá en un archivo por lotes.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-02-27 20:11:56
Técnicas que recogí de otras respuestas:
Hace que un archivo de 0 bytes sea una forma muy clara y compatible con versiones anteriores:
type nul >EmptyFile.txt
Idea vía: anónimo, Danny Backett, posiblemente otros, yo mismo inspirado por el trabajo de JdeBP
Un archivo de 0 bytes de otra manera , es compatible con versiones anteriores:
REM. >EmptyFile.txt
Idea vía: Johannes
Un archivo de 0 bytes 3rd way compatible con versiones anteriores, también:
echo. 2>EmptyFile.txt
Idea vía: TheSmurf
Un archivo de 0 bytes la forma sistemática probablemente disponible desde Windows 2000:
fsutil file createnew EmptyFile.txt 0
Idea vía: Emm
Un archivo de 0 bytes sobrescribiendo archivos de solo lectura
ATTRIB -R filename.ext>NUL
(CD.>filename.ext)2>NUL
Idea vía: copyitright
Una sola nueva línea (2 bytes: 0x0D 0x0A
en notación hexadecimal , alternativamente escrita como \r\n
):
echo.>AlmostEmptyFile.txt
Nota: no espacio entre echo
, .
y >
.
Idea vía: ¿Cómo se puede hacer eco de una nueva línea en archivos por lotes?
Editar Parece que cualquier comando no válido redirigido a un archivo crearía un archivo vacío. heh, una característica! compatibilidad: uknown
TheInvisibleFeature <nul >EmptyFile.txt
Un archivo de 0 bytes: comando no válido / con un nombre aleatorio (compatibilidad: uknown):
%RANDOM%-%TIME:~6,5% <nul >EmptyFile.txt
Vía: gran fuente para aleatorio por Hung Huynh
Edit 2 Andriy M señala la forma probablemente más divertida / provocadora de lograr esto a través de un comando no válido
A 0 bytes file: invalid command / the funky way (compatibility: unknown)
*>EmptyFile.txt
Idea vía: Andriy M
A 0 bytes file 4th-coming way :
break > file.txt
Idea vía: foxidrive gracias a comentario de Doble Gras !
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 11:33:26
REM. > vaciar.file
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-04-12 09:13:41
Si existe la posibilidad de que el archivo a escribir ya exista y sea de solo lectura, utilice el siguiente código:
ATTRIB -R filename.ext
CD .>filename.ext
Si no existe ningún archivo, simplemente haga:
CD .>filename.ext
(código actualizado/cambiado de acuerdo con el comentario de DodgyCodeException)
Para suprimir cualquier error que pueda surgir:
ATTRIB -R filename.ext>NUL
(CD .>filename.ext)2>NUL
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-05 14:00:22
fsutil file createnew file.cmd 0
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-18 13:22:48
Uno más para agregar a los libros - corto y dulce para escribir.
break>file.txt
break>"file with spaces in name.txt"
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-25 06:54:28
Puede usar un comando TYPE
en lugar de COPY
. Prueba esto:
TYPE File1.txt>File2.txt
Donde File1.txt
está vacío.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-02-27 20:12:09
También puede usar SET
para crear un archivo null byte
de la siguiente manera
set x=x > EmptyFile.txt
O si no desea crear una variable adicional reasignar una variable existente como
set PROMPT=%PROMPT% > EmptyFile.txt
O así:
set "PROMPT=%PROMPT%" > EmptyFile.txt
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-07 12:02:13
La forma más fácil es:
echo. > Filename.txt
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-10 22:16:13