1.

Solve : Batch file for finding files on network shared drive?

Answer»

Hi, I'm new to the forums, but I would like to ask a question and hopefully get some help if I may;

I am trying to complie a batch file to find and then list a NUMBER of large files, lets say the 30 largest on a network shared drive at work. I use UNIX on a daily basis and the command I would use within UNIX is:

find . -size +9999999c  2> /dev/null -exec ls -l {} \; |sort -n +4 |tail -30

However, I realise that this may not work within DOS.

Can anyone help me because I've been searching round for a while and I've been able to find nothing at all. don't you know *nix tools have been ported to Win32? Download from here. (especially coreutils, findutils )No, I wasn't aware of that.. The only issue may be, that our laptops are so locked down by the admins that I may not be able to do much with anything on that list..!!As expected, I am unable to install anything from that page 

The lockdown on my machine here means I cannot write any values to the registry when attempting to install. So, if anyone does know of a way to answer my question using DOS commands in a batch file, I'd really, really appreciate it.

Thanks for the link though, this may help me with a similar issue at home!! Quote from: icage on April 08, 2010, 04:37:35 AM

As expected, I am unable to install anything from that page 

The lockdown on my machine here means I cannot write any values to the registry when attempting to install. So, if anyone does know of a way to answer my question using DOS commands in a batch file, I'd really, really appreciate it.

Thanks for the link though, this may help me with a similar issue at home!!
you can download from home, and save to thumb drive. (you can bring all the .exe installed into 1 thumb drive). also, only if your laptop's usb drive is not locked down by you admin as well Another big fat zero... I can't believe how petty the admins actually are, I've tried 3 USB drives in my work machine, none of them are showing up, so I CALLED our IT Support and I'm told they locked the USB ports down for "security reasons"

since your company has such as security policy, then there must be procedures when you need to use tools that are third party. Request permission from your boss to authorise the use of such tools (If its really for your work). Tell them these are tools that will increase your productivity. If its still a gone case, you will need to learn some DOS batching or vbscripting. Well, I did have a go at a batch file, but it's only slightly what I'd hoped for:

echo off
echo.
DIR Z: /A :RSA -D /P sortorder -S
pause

(I have the network drive mapped to Z: in my drives list)

This sort of works fine, but it lists the directories and then the files in no particular order, I'd prefer it not to list the directiories, but to interrogate them for large files and then print out a list of filenames starting with the largest file first.

Quote from: icage on April 08, 2010, 07:42:50 AM

This sort of works fine, but it lists the directories and then the files in no particular order, I'd prefer it not to list the directiories, but to interrogate them for large files and then print out a list of filenames starting with the largest file first.


well to remove the directories try the following:

DIR Z: /A -D /P sortorder -S

for more information type DIR /? Quote
find . -size +9999999c  2> /dev/null -exec ls -l {} \; |sort -n +4 |tail -30

Don't really understand the whole command, but your post text was helpful. This may do what you want:

Code: [Select]echo off
setlocal enabledelayedexpansion

if exist dirList.txt del dirList.txt
if exist sortedDirList del sortedDirList

for /f "tokens=* delims=" %%i in ('dir c:\windows\system32 /s /b') do (
  if %%~zi GEQ 9999999 echo %%~zi %%~dpni >> dirList.txt
)

sort /r dirlist.txt /o sortedDirList.txt

for /f "tokens=1-2" %%i in (sortedDirList.txt) do (
  echo %%i %%j
  set /a count+=1
  if !count! EQU 30 goto :eof
)

You can change c:\windows\system32 to any valid directory.

Good luck. 
Sidewinder, that's great, I just copied and pasted your code and then ran it as a batch file to test it, it worked brilliantly, however, if I try and replace c:\windows\system32 with the drive I need to CHECK, it doesn't seem to do anything at all...

I know the screen stays blank whether it's doing anything or not, but there is no text file created when I try and use iton my network drive..

I have tried \\share\folder and z:\share\folder (for share\folder - this is my networked drive).

Any ideas?I think you just have to be patient. I tested on a network directory (wireless) with 891 files. The script ran 25 minutes.

I inadvertently left out a few file extensions and there is a major logic error because NUMBERS in batch are treated as text and do not right align which will throw off the sort. I added logic to fix this but now you need to use the choice command for this work. Sorry for the inconvenience.

Code: [Select]echo off
setlocal enabledelayedexpansion

if exist dirList.txt del dirList.txt
if exist sortedDirList.txt del sortedDirList.txt

for /f "tokens=* delims=" %%i in ('dir c:\windows\system32 /s /b') do (
  call :ZeroFill %%~zi
  if %%~zi GEQ 9999999 echo !var! %%~dpnxi >> dirList.txt
)

sort /r dirList.txt /o sortedDirList.txt

for /f "tokens=* delims=" %%i in (sortedDirList.txt) do (
  echo %%i
  set /a count+=1
  if !count! EQU 30 goto :eof
)
goto :eof

:ZeroFill
  echo;;|choice /c=%1; set > p.bat
  set ct=0
  call p.bat

  for %%v in (%[%) do call set /a ct=%%ct%%+1

  set [=
  del p.bat > nul
 
  set /a pad=12 - %ct%
  if %pad% equ 11 set var=00000000000%1
  if %pad% equ 10 set var=0000000000%1
  if %pad% equ 9 set var=000000000%1
  if %pad% equ 8 set var=00000000%1
  if %pad% equ 7 set var=0000000%1
  if %pad% equ 6 set var=000000%1
  if %pad% equ 5 set var=00000%1
  if %pad% equ 4 set var=0000%1
  if %pad% equ 3 set var=000%1
  if %pad% equ 2 set var=00%1
  if %pad% equ 1 set var=0%1
  goto :eof

Good luck.


Discussion

No Comment Found