Jump to content

Need Batchfile (rename and export)


KNARZ

Recommended Posts

hi

can someone help me to write a short batchfile which:

rename the WindowsXP-KBXXXXX-x86-XXX.exe files

to:

KBXXXXXX.EXE

and than export the files(names) to something like this...

%CMD% %SOURCE%KBXXXXXX.EXE %INT%%PATH%

To explai what the var. means:

SET CMD=START /WAIT

SET INT=/Q -INTEGRATE:

SET SOURCE=H:\UPDATES\

SET PATH=H:\XPCD\

_________

rename WindowsXP-*-x86-XXX.exe KB*.EXE

doesn't work... i thought that should work... but no way...

_________

i want a batch... that rename the files and export it with parameters in the beginning of the file and in the end

similar example;

WindowsXP333.exe

to

WIN333.EXE

and export (text)file:

like this one...

PAR1 WIN333.EXE PAR2

XXX means the KB number and/or language...

Link to comment
Share on other sites


This should get you started. It will rename the hotfixes that are in the %SOURCE% directory and output a list to export.txt in your format.

SET CMD=START /WAIT
SET INT=/Q -INTEGRATE:
SET SOURCE=H:\UPDATES\
SET PATH=H:\XPCD\

del export.txt 2>nul

for /f "tokens=1,2 delims=-" %%I in ('dir /b %SOURCE%\windowsxp-kb*.exe') do (
   ren %SOURCE%%%I-%%J*.EXE %%J.EXE
   echo %CMD% %SOURCE%%%J.EXE %INT%%PATH%>>export.txt
)

Link to comment
Share on other sites

really thanks... ;)

i had to modified something because of the '(' and ')'

but now:

the renaming works perfect... but exporting not that good...

i modified a little bit more (as i can understand the soruce gg)

to:

DEL EXPORT.TXT 2>NUL

FOR /F "TOKENS=1,2 DELIMS=-" %%I IN ('DIR /B WINDOWSXP-KB*.EXE') DO REN %%I-%%J*.EXE %%J.EXE

ECHO %CMD% %SOURCE%%%J.EXE %INT%%PATH% >> EXPORT.TXT

in exporting.txt the KBXXXX won't be inserted

export.txt put's out (only 1 line):

START /WAIT H:\XXX\%J.EXE /Q -INTEGRATE:H:\XPCD\
Link to comment
Share on other sites

The REN and ECHO lines need to be in parenthesis because they are both part of the DO loop. Enclosing lines in parenthesis like that is a way of executing multiple lines of code using commands like IF and DO. An alternative way is to us the '&' character to separate multiple commands like...

FOR /F "TOKENS=1,2 DELIMS=-" %%I IN ('DIR /B WINDOWSXP-KB*.EXE') DO REN %%I-%%J*.EXE %%J.EXE & ECHO %CMD% %SOURCE%%%J.EXE %INT%%PATH% >> EXPORT.TXT

This must all be on one line. This way makes the code harder for someone else to read (if that matters) but it works all the same.

Link to comment
Share on other sites

THX =) :thumbup:thumbup:thumbup

now i got it in that way that i wanted ;)

DEL EXPORT.TXT 2>NUL

ECHO SET CMD=START /WAIT >> EXPORT.TXT

ECHO SET PAR=/Q -INTEGRATE: >> EXPORT.TXT

ECHO SET SOURCE=H:\XXX\ >> EXPORT.TXT

ECHO SET TO=H:\XPCD\ >> EXPORT.TXT

ECHO SET START=%%CMD%% %%SOURCE%% >> EXPORT.TXT

ECHO SET END=%%PAR%%%%TO% >> EXPORT.TXT

ECHO. >> EXPORT.TXT

ECHO Microsoft Security Bulletin Summary für %date:~3,-5% / %date:~-4% >> EXPORT.TXT

ECHO. >> EXPORT.TXT

FOR /F "TOKENS=1,2 DELIMS=-" %%I IN ('DIR /B WINDOWSXP-KB*.EXE') DO REN %%I-%%J*.EXE %%J.EXE & ECHO %%START%%%%J.EXE %%END%% >> EXPORT.TXT

ECHO. >> EXPORT.TXT

ECHO Erstellt am: %date% um %time:~0,-6% >> EXPORT.TXT

Link to comment
Share on other sites

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...