How to? GLOBAL question

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
I want to use GLOBAL on a whole drive but exclude a particiulr subtree. How is htis best handled?

C:\> SET nLen=%USERPROFILE\Favorites
C:\> GLOBAL /I /Q /H gosub fldr

IFF %@left[%nLen,%_CWD] != "%USERPROFILE\Favorites" THEN
.... process directory

TCC 15.01.52 x64 Windows 7 [Version 6.1.7601]
TCC Build 52 Windows 7 Build 7601 Service Pack 1
global /i /q /h if isfile *.url if %@index[%_cwd,%userprofile\Favorites] lt 0 move /md /r /p *.url %userprofile\Favorites\URLs\

Works great; However What if I want to not transverse these trees:
C:\My Programs
C:\Program Files
C:\Program Files (x86)
C:\Users\All Users\Microsoft\Windows\Start Menu

Once I get this to work - I'll work on DOC and other "often" files.
Method 1 : create a file dir_list of all directory trees to be processed; then do
for %d in (@dir_list) (pushd %d %+ global ... %+ popd )
Method 2 : if there are NO hidden directories you want to actually process, use the method of the old EXCEPT command:
- create a file listing the top directory of each not to process tree: no_tree
- save the current state of their H attribute:
for /r %d in (@no_tree) if %attrib[@d,H] EQ 1 echo %d >! was_hidden
- HIDE them:
attrib a:-h +H @no_tree
- use GLOBAL without /H option:
global /i /q if isfile *.url if %@index[%_cwd,%userprofile\Favorites] lt 0 move /md /r /p *.url %userprofile\Favorites\URLs\
- unhide all that you hid above:
attrib -h @no_tree
- rehide as needed:
if isfile was_hidden attrib +H @was_hidden

BTW, it is possible to create just a list of directories which you had to actually hide, and only unhide those, possibly by the report of the ATTRIB command which hid them, saving a tiny bit of time.

Method 3 : Create a root-level directory, and populate it with symlinks or junctions to each tree to be actually processed. Now you can use GLOBAL in this directory. This is just an alternate implementation of the underlying principle of Method 1.

Method 4 : In the original GLOBAL method, check every directory's location against ALL possible excluded paths, instead of just one or two...

Comparison: Methods1 1 and 3 have difficulty if there is a directory which is to be processed but which has one or more subdirectories that are to be excluded, e.g., C:\users
I think so. The line after the ProcessFldr label should start with IFF, shouldn't it?
I think it would be simpler using an indirect file ("@file") of the list of directory trees to be ignored. This would do it (CAVEAT EMPTOR):

GLOBAL /H /I /Q gosub DO_IT

if not isfile *.url return
do dir in @ignore_list
  if %@index[%_cwd,%dir] GE 0 return
move ...