Jump to content

two forfiles problems


Recommended Posts

Hi, I'm not a programmer, more like a "one liner". :D

I'm trying to integrate a bunch of KB (in KB directory) to an XP source (in c:\temp\ris\) under Win7 using FORFILE. My batch file reads

FORFILES -pKB -m*.exe -c"KB\@FILE /integrate:c:\temp\ris\ /quiet /passive"

once started, it tries to install the 1st KB onto my running system (and fails of course which is better so) then goes to the next one.

The lines "KB\KBxxxxxxx.exe /integrate:c:\temp\ris\ /quiet /passive" do work when typed manually.

so the KB are found and launched but not with "/integrate".

i've used switches before for other tasks (like -c"deltree /y c:\blablabla\@file\blablabla" ) but it doesn't seem to like it here. Am I missing something ? Yes.

Also unrelated; FORFILES doesn't pick up directories that have extensions.

I mean you can't process files that are in

c:\directory1.aaa\....

c:\directoty2.aaa\...

it simply can't list them even using mask "-m*.". Any known workaround ?

Edited by Ponch
Link to comment
Share on other sites


I take it that when you state 2FILE you mean @file, however because forfiles returns variables in double quotes I'd be inclined to use @path

FORFILES /P KB /M *.exe /C "@path /quiet /passive /integrate:C:\temp\ris"

There should be a space between the forfiles switch and the data following it.

Link to comment
Share on other sites

I corrected my typo.

@path will not launch the exe file, it will just report its path (which is the same for all the exe). Or should I from that line launch an other batch launching the exe with the exe as argument?

I don't know how or why, the version I have needs dash instead of slash and no space after switch. I don't kow where to get a newer version if any.

I think I'll do them by hand, it'll take me 1/2 hour.

Edited by Ponch
Link to comment
Share on other sites

Try this and tell me what it says:

forfiles /P KB /M *.exe /C "cmd /c echo @path"

BTW - [Windows 7]

Microsoft Windows [Version 6.1.7601]

Copyright © 2009 Microsoft Corporation. All rights reserved.

C:\Users\Yzöwl>forfiles /?

FORFILES [/P pathname] [/M searchmask]

[/C command] [/D [+ | -] {dd/MM/yyyy | dd}]

Description:

Selects a file (or set of files) and executes a

command on that file. This is helpful for batch jobs.

Parameter List:

/P pathname Indicates the path to start searching.

The default folder is the current working

directory (.).

/M searchmask Searches files according to a searchmask.

The default searchmask is '*' .

/S Instructs forfiles to recurse into

subdirectories. Like "DIR /S".

/C command Indicates the command to execute for each file.

Command strings should be wrapped in double

quotes.

The default command is "cmd /c echo @file".

The following variables can be used in the

command string:

@file - returns the name of the file.

@fname - returns the file name without

extension.

@ext - returns only the extension of the

file.

@path - returns the full path of the file.

@relpath - returns the relative path of the

file.

@isdir - returns "TRUE" if a file type is

a directory, and "FALSE" for files.

@fsize - returns the size of the file in

bytes.

@fdate - returns the last modified date of the

file.

@ftime - returns the last modified time of the

file.

To include special characters in the command

line, use the hexadecimal code for the character

in 0xHH format (ex. 0x09 for tab). Internal

CMD.exe commands should be preceded with

"cmd /c".

/D date Selects files with a last modified date greater

than or equal to (+), or less than or equal to

(-), the specified date using the

"dd/MM/yyyy" format; or selects files with a

last modified date greater than or equal to (+)

the current date plus "dd" days, or less than or

equal to (-) the current date minus "dd" days. A

valid "dd" number of days can be any number in

the range of 0 - 32768.

"+" is taken as default sign if not specified.

/? Displays this help message.

Examples:

FORFILES /?

FORFILES

FORFILES /P C:\WINDOWS /S /M DNS*.*

FORFILES /S /M *.txt /C "cmd /c type @file | more"

FORFILES /P C:\ /S /M *.bat

FORFILES /D -30 /M *.exe

/C "cmd /c echo @path 0x09 was changed 30 days ago"

FORFILES /D 01/01/2001

/C "cmd /c echo @fname is new since Jan 1st 2001"

FORFILES /D +29/3/2012 /C "cmd /c echo @fname is new today"

FORFILES /M *.exe /D +1

FORFILES /S /M *.doc /C "cmd /c echo @fsize"

FORFILES /M *.txt /C "cmd /c if @isdir==FALSE notepad.exe @file"

Both forward slash and a hyphen work on my system anyhow.

forfiles -P KB -M *.exe -C "cmd /c echo @path"

If you wish to try it with your non Win7 functioning command try this:

forfiles -PKB -M*.exe -C"cmd /c echo @path"

In any case it should show the full path including the executable file name and extension.

Link to comment
Share on other sites

Thanks for enlighting me big time on this small subject.

Seems (well, I knew that) I have an old version that is comming of the Win2000 Ressource Kit. What I did not know is that forfiles now comes included in Vista and Win7 and so copying the old file next to by batch was sabotaging myself.

That old version (I've seen loads of remark about that on the Technet site but not any explanation) has quite a different behaviour; ,i.e.

- is using only hyphens before switches,

- doesn't accept a space between switch and argument

- is picky on having variables in uppercase (@PATH is ok, "@path" is not).

- the @PATH only gives a full path when the newer version gives full path including file name.

- does not pick up "directories with extensions" (see 1st post)

- returns variables without quotes.

Using the newer version,

forfiles /P KB /M *.exe /C "cmd /c echo @path"

returns the list of "C:\temp\KB\KBxxxxxxx.exe" , but unfortunately, it still doesn't pick my /integrate switch so I've done that thing manually now.

And unsurprisingly, MS "prevents" you from using the newer version under XP.

Thanks.

Edited by Ponch
Link to comment
Share on other sites

returns the list of "C:\temp\KB\KBxxxxxxx.exe" , but unfortunately, it still doesn't pick my /integrate switch so I've done that thing manually now.

And unsurprisingly, MS "prevents" you from using the newer version under XP.

I am missing the "base" assumption that forfiles is actually *needeed*.

Won't a more "Normal" FOR /F %%A in ('DIR /B /S *.exe' ) DO ( do as well? :unsure:

jaclaz

Link to comment
Share on other sites

I am missing the "base" assumption that forfiles is actually *needeed*.

Won't a more "Normal" FOR /F %%A in ('DIR /B /S *.exe' ) DO ( do as well? :unsure:

jaclaz

Well other than it wasn't the question, you're correct in that it isn't actually required.

mind you I'd have considered 'more normal' as, FOR %%A IN (*.exe) DO ( :yes:

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