1.

Solve : please need help with a batch file!?

Answer»

Hi!
I need your help!
i want to do a batch file to CHANGE the permissions of directorys.

For each directory I want to execute a program with this directoryname as parameter...
For example:
directory1
directory2
directory3
direcotry4
-----------> for "each_directory" do "programmtochangerights -f -d user=direcory1 owner=administrator"
The directory name should be a variable that i could put in the parameter of the executed file...

Can anyone of you please help me??

Using additional FORMS of for
If command extensions are enabled (that is, the default), the FOLLOWING additional forms of for are supported:
[ch8226] Directories only
If set contains wildcards (* and ?), the specified command executes for each directory (instead of a set of files in a specified directory) that matches set. The syntax is:
for /D {%% | %}variable in (set) do command [CommandLineOptions]

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/b atch.mspxWhen you say
Quote

The directory name should be a variable that i could put in the parameter of the executed file...
I'm not sure exactly what you mean, but if you put the following in a batch file I think this should do what you want:
Code: [Select]for /f %%a in ('dir /b /ad') do (echo programmtochangerights -f -d user=%%a owner=administrator)This code ASSUMES that you want the "user=" line to be the directory name as in your example. If this is not what you wanted, please provide more details.
I currently have it output what the command would actually be so you can check the output. To have it actually run the command, just take out the word "echo".

This will process all directories from the directory the command is run in. Also note that if any of the directories have spaces in them, you may need to put quotes around the %%a ... but since I don't KNOW the program you are using this may not be supported or necessary.If you have a list of given directories then you can use:

Code: [Select]set dirs=,
set dirs=%dirs%"directory1",
set dirs=%dirs%"directory2",
set dirs=%dirs%"directory3",
set dirs=%dirs%"directory4",
set dirs=%dirs%"directory5",
for %%a in (%dirs%) do programmtochangerights -f -d user=%%a owner=administrator
Hope this helps


Discussion

No Comment Found