Write current Directory to a text file

Asked

Viewed 3,791 times

2

In a batch program I have:

echo Date >c:\users\...\testecmd.txt

Write the current date in a text file.

Assuming I don’t know where is the directory in which the auto executable is, how do I get it to call the Current directory, in place of "c: users... testecmd.txt" and write this same directory instead of Date ?

echo "c:\Diretorio\atual\" >c:\diretorio\atual\testecmd.txt

2 answers

4


%CD% is the environment variable that contains the current directory. And if you want to access a file in the current directory, you can use the .:

echo %CD% > .\testecmd.txt

The archive testecmd.txt will be created in the current directory, and its contents will be the full name of the current directory of the command line.

0


  • You don’t even have to give the echo in the variable %cd% to get the current directory/folder, use the cd.

Has command to do this direct, use the command cd (Check Directory), bat/cmd or command line, direct.

CD>.\testcmd.txt

inserir a descrição da imagem aqui

Obs.:

[commando: cd ] [operator: & ] [commenting: :: ]

             cd            &                :: exibir o caminho da pasta/diretório atual na tela 

CD>.\testcmd.txt


cd & :: exibir o caminho da pasta/diretório atual na tela
G:\SO_pt-BR\Q113666

cd>.\testcmd.txt & :: redireciona a saída para o arquivo testcmd.txt

cd | clip & :: copia/move a saída do comando cd para o seu clipboard (Crtl+C)


Browser other questions tagged

You are not signed in. Login or sign up in order to post.