How to list folder files on the network

Asked

Viewed 9,720 times

4

Context:
Sometimes every day I need to gather information from folders on the network, where it has several subfolders and files.

Need:
I need to gather that information faster, so I thought put a . bat in the folder Sentto windows (C: Users name Appdata Roaming Microsoft Windows Sendto).
Path used in Windows7, other windows versions might be another path.

I currently perform this via CMD by command:

dir /s /b \\caminho-rede\pasta\pastaArquivos | clip

Then through Sendto by right-clicking the folder pasture, automatically would have the information in my Clipboard.

inserir a descrição da imagem aqui

In the form below, it works locally, but not via network:

set caminho=%cd%
dir %caminho% /s /b |clip
exit

However return to me:

'\path-network folder fileArchives' CMD.EXE was started having the path above as current folder. There is no support for UNC paths. Standardizing for Windows folder.

Observing: If possible I would like you to return only the list of file paths .EXE and .ZIP

1 answer

4


To access UNC paths from the command prompt, Windows provides the command pushd, which creates a temporary path access letter (in reverse alphabetical order from Z:) and changes the current directory to this new letter/path.

After using the path, you can use the command popd to clear this path from the stack of temporary paths.

The UNC path error message will always appear while running the script as you will trigger it through the Path, the initial path of the CMD.EXE process will always be invalid.

Also, due to the initial path, the variable %cd%, indicated in your code to access the current file path bat, won’t work.

The solution is to switch to the variable %1, which obtains the network path from the parameter informed by the execution through the Path.

To get the file-only list .EXE and .ZIP, a possible solution is to filter the output of the command dir using the command findstr before sending it to the clip command.

The complete script is as follows:

set caminho=%1
pushd %caminho%
dir /s /b | findstr /i /e "exe zip" | clip
popd
exit

Observing: the paths returned by the script will start with a disk letter that does not exist on the system (temporary) and not with the network path. Example:

Instead of: \\caminho-rede\pasta\pastaArquivos

May appear: Z:\pasta\pastaArquivos

It is necessary to verify if this behavior meets your need.

Links to the documentation:

How to use commands pushd and popd:
https://support.microsoft.com/en-us/kb/317379

Of command findstr:
https://technet.microsoft.com/en-us/library/cc732459(WS.10). aspx

  • Actually appears the temporary drive, X:\pasta\pastaArquivos, but this in my case does not make the slightest difference, solved my problem and still if I need to change I learned of the commands pushd, popd and %1 I didn’t know. Thanks @Gomiero.

Browser other questions tagged

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