spacesurfer Posted December 16, 2007 Posted December 16, 2007 (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.cmdcd /d %~dp0if not exist Collected_Files md Collected_FilesDEL "%cd%\Collected_Files\*.*" /qfor /F "Tokens=1" %%i IN ('FINDSTR "." files.txt') DO Call :copyfiles "%%i"goto :exit:copyfilescopy %1 "%cd%\Collected_Files":exitThe 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 December 16, 2007 by spacesurfer
Yzöwl Posted December 16, 2007 Posted December 16, 2007 Does this help?@ECHO OFFPUSHD %~DP0RD/S/Q COLLECTED_FILES 2>NULMD Collected_FilesFOR /F %%? IN (FILES.TXT) DO CALL COPY %%? COLLECTED_FILES>NUL 2>&1
spacesurfer Posted December 17, 2007 Author Posted December 17, 2007 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.
Yzöwl Posted December 17, 2007 Posted December 17, 2007 Yes, that's exactly what it does!It preventsSTDOUT 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now