How to list folder files on the network

3
  

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

     

Need:
  I need to gather this information faster, so I thought of   put a .bat in the SentTo folder in windows   (C: \ Users \ username \ AppData \ Roaming \ Microsoft \ Windows \ SendTo). Path used in Windows7, other versions of windows may be another path.

I currently do this via CMD by the command:

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

Then through SendTo when you right-click the Files folder , it would automatically have the information in my clipboard.

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

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

However it returns me:

  

'\\ path \ net \ folder \ folder \ CMD.EXE files started having the   above as the current folder. UNC paths are not supported.   Standardizing for Windows folder.

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

asked by anonymous 20.01.2016 / 18:05

1 answer

2

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 that path. new letter / path.

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

The UNC path error message will always appear during the execution of the script, because as you will fire it through SendTo , 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 path of the bat file, will not work.

The solution is to exchange for the variable %1 , which gets the network path from the parameter informed by the execution through SendTo .

To obtain a list of .EXE and .ZIP files, a possible solution is to filter the output of the dir command by using the findstr command before send it to the clip command.

The complete script looks like this:

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

Note: The paths returned by the script will start with a non-existent disk letter in the (temporary) system and not with the network path. Example:

Instead of: \caminho-rede\pasta\pastaArquivos

You may see: Z:\pasta\pastaArquivos

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

Links to the documentation:

How to use the pushd and popd commands:
link

From the findstr command: link

    
26.01.2016 / 05:37