5

I wrote a very simple Batch file that directs output to a file. Here's the text body:

DATE /T > FileTreeList.txt
TIME /T >> FileTreeList.txt
cd >> FileTreeList.txt
tree /f /a >> FileTreeList.txt

When I run the Batch File in a directory that has a lot of folders and files, the output file (FileTreeList.txt) truncates at ~621KB. If I run the Batch File from command mode and direct output to a file, I get the same results. However, if I let the results display on screen, it shows all the results.

Why does it happen and how to fix it?

Mephy
  • 2,978
  • 3
  • 25
  • 31
JeffL
  • 51
  • 2
  • 3
    Do you get the same results if you enclose all the commands in parentheses and only open FileTreeList.txt once for writing? `(date /t & time /t & cd & tree /f /a) >FileTreeList.txt` – rojo Aug 31 '15 at 21:05
  • Are you sure that the batch file with the 4 lines above runs with same privileges (= same user account) as when you run the last command manually from within a command prompt window with results output to window? This is important in case of traverse access permissions on all directories which could be an explanation for different tree lists. – Mofi Sep 01 '15 at 05:57
  • I tried your four lines in a batch file with switching current directory first to root of drive C: and writing the output of the four commands to `F:\Temp\FileTreeList.txt` on Windows 7 x64. The list file had 8.3 MB after batch file execution finished containing the entire tree. – Mofi Sep 01 '15 at 12:56

2 Answers2

1

Probably your hard drive is full and only has a ~621KB of free space ;)

Paul
  • 2,620
  • 2
  • 17
  • 27
0

I guess that is the tree of the current folder. If you want a bigger file try going to %HOMEDRIVE% and list all the folders/files in the drive. Try this code:

@rem Turn the command line (C:>COMMAND before every command)
@echo off
rem Go to the homedrive (if not currently in)
if "%cd:~0,1%"=="%homedrive:~0,1%" call %homedrive:~0,1%:
rem go to the root of homedrive
cd %HOMEDRIVE%
rem execute your code
DATE /T > FileTreeList.txt
TIME /T >> FileTreeList.txt
cd >> FileTreeList.txt
tree /f /a >> FileTreeList.txt