开发者

Windows batch file: rename files (possibly in multiple folders) based on input file (of target filenames)

开发者 https://www.devze.com 2023-04-10 21:01 出处:网络
I am a Batch-newbie, so please accept my apologies and Thanks in advance ! This \"tool\" is to automate the slimming down of Windows (XP) by disabling certain system driver, DLL and EXE files.Instead

I am a Batch-newbie, so please accept my apologies and Thanks in advance !

This "tool" is to automate the slimming down of Windows (XP) by disabling certain system driver, DLL and EXE files. Instead of outright deletion, I wish to rename-in-place, thus "removing" them from the OS, but no开发者_如何转开发t losing sight of where they belong (should any need to be "restored"). Renaming is accomplished by appending a new suffix to the existing filename (eg: "wdmaud.drv.group_1") The renaming suffix should be another input variable.

The target-list is approx. 1100 files long (divided into various groups/phases), so manual renaming is out of the question. Each group will be processed in a separate run of the batch file, varying the target-list input file for each execution.

Target-list is plain text file, one filename per line (no other data in the files). Number of entries per group varies. Target list will look like this:

    -- example start --
    netapi.dll
    netcfgx.dll 
    netdde.exe 
    netevent.dll 
    neth.dll
    netid.dll
    netrap.dll
    nic1394.sys
    -- example end --

Filenames may be in UPPER, lower, or MiXeD case. The files may be present in more than one folder in the C:\Windows hierarchy - or may not be present at all. If a file is not found anywhere in the system, it's name should be written to a text file, one-entry-per-line.

The specific folders of interest are:

    C:\WINDOWS\
    C:\WINDOWS\system\
    C:\WINDOWS\system32\
    C:\WINDOWS\system32\dllcache
    C:\WINDOWS\system32\drivers

The renaming will be done by connecting the target OS drive to another XP computer, so locked system files should not be a problem.

Any help you can offer will be greatly appreciated.


a double FOR loop may help you.. this is a very simple example, just to get you started

for /f "tokens=*" %%f in (%targetlist%) do (
  for /f "tokens=*" %%d in (%dirlist%) do (
    if exist "%%d\%%f" echo %%f found in %%d
  )
)

see HELP FOR.

0

精彩评论

暂无评论...
验证码 换一张
取 消