Jump to content

Recommended Posts

Posted (edited)

Here's what I'm trying to do: I want to collect system files (copy them) to a temp folder in order to reshack them. The list of files are in a text file called files.txt. Th e location of the files are in either windows or system32 folder. The files.txt also includes the compressed form so I can also extract them from an ISO automatically. Here's what my text file looks like.

files.txt (Partial list)

%windir%\explorer.exe	explorer.ex_
%windir%\system32\taskmgr.exe taskmgr.ex_
%windir%\system32\shell32.dll shell32.dl_

The first column in text file lists the location where I want the file to come from. The second column is the compressed form in ISO. Thus, I'm using the tokens=1 command to specify the first column to collect system files, and tokens=2 to extract from ISO.

Here is the batch script I use to collect files (copy them) to a temp location.

collect_files.cmd

cd /d %~dp0
if not exist Collected_Files md Collected_Files
DEL "%cd%\Collected_Files\*.*" /q
for /F "Tokens=1" %%i IN ('FINDSTR "." files.txt') DO Call :copyfiles "%%i"
goto :exit

:copyfiles
copy %1 "%cd%\Collected_Files"

:exit

The line I need help with is "for /F "Tokens=1" %%i IN ('FINDSTR "." files.txt') DO Call :copyfiles "%%i"". This works perfectly without errors, but I'm not sure if 'FINDSTR "." files.txt' is the correct way of doing it.

Is there a better way of going down the list of first column than using "."?

Edited by spacesurfer

Posted

Does this help?

@ECHO OFF
PUSHD %~DP0
RD/S/Q COLLECTED_FILES 2>NUL
MD Collected_Files
FOR /F %%? IN (FILES.TXT) DO CALL COPY %%? COLLECTED_FILES>NUL 2>&1

Posted

The script works, Yzowl. Thanks.

Obviously, I can't use long filenames with spaces - there was only one I had in the list and I used the 8.3 format to circumvent this problem.

I added "Tokens=2" to your FOR command to get the compressed files - seems to work okay.

One question though: what does the 2>NUL do and >NUL do? It seems to prevent the confirmation that the file was copied or not copied.

Posted

Yes, that's exactly what it does!

It prevents

  • STDOUT standard output being echoed to the screen by redirecting it to a nul, non-existing, device >NUL or more precisely 1>NUL.
  • STDERR standard errors being echoed to the screen by redirecting it to a nul, non-existing, device 2>NUL or also 2>&1 meaning the same nul device as the STDOUT was redirected.

They can obviously be removed if you wish to see those things echod to the console.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...