Should be an easy batch file modification?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
TomBombo
Posts: 5
Joined: 12 Aug 2013 21:54

Should be an easy batch file modification?

#1 Post by TomBombo » 15 Aug 2013 01:43

HI guys

I need help with a a batch file modifications. Should be pretty easy with someone with a bit of experience but I am not great at this yet.

1.

I have this

Code: Select all

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (f.txt) do (
set /a N+=1
echo icacls ^"%%a^" ^>^> results.txt >>batch.txt
)


This works fine but I want to change it so I can run it on mutiple input files and output it to corresponding filenames.
e.g. I have files input called
depth-1.txt and depth-2.txt and depth-3.txt and want the output to be results-1.txt & batch-1.bat and results-2.txt & batch-2.bat etc so I need to use the input parameter twice.
I need to run this on a lot of folders! So it would save a lot of tedious renaming everytime.
Thanks

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Should be an easy batch file modification?

#2 Post by penpen » 15 Aug 2013 02:37

Maybe this may work:

Code: Select all

@echo off
setLocal EnableDelayedExpansion

for /L %%b in (1,1,3) do (
   for /f "tokens=* usebackq delims= " %%a in ("depth-%%b.txt") do (
      set /a N+=1
      (echo icacls ^"%%a^" ^>^> results-%%b.txt) >> "batch-%%b.bat "
   )
)


penpen

Edit: Just saw, that i made a flaw; corrected:
results.txt -> results-%%b.txt
results-%%b.txt -> batch-%%b.bat
Last edited by penpen on 15 Aug 2013 03:38, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Should be an easy batch file modification?

#3 Post by foxidrive » 15 Aug 2013 03:08

This should work - no need for delayed expansion.

Code: Select all

@echo off
for %%x in (depth-*.txt) do (
   for /f "tokens=2 delims=-" %%y in ("%%~nx") do (
      for /f "delims=" %%z in (' type "%%x" ') do (
        echo icacls ^"%%z^" ^>^> results-%%y.txt >>batch-%%y.txt
      )
   )
)


TomBombo
Posts: 5
Joined: 12 Aug 2013 21:54

Re: Should be an easy batch file modification?

#4 Post by TomBombo » 15 Aug 2013 18:48

Thanks guys..
Working like a charm..

Much appreciated!

Is this a good place where I can request help for processing my icacl returns or should something more powerful like Powershell should do that?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Should be an easy batch file modification?

#5 Post by foxidrive » 15 Aug 2013 21:26

penpen wrote:Maybe this may work:

Code: Select all

@echo off
setLocal EnableDelayedExpansion

for /L %%b in (1,1,3) do (


penpen


I was aware that the level of subdirectory is variable (from a different thread, the files are lists of paths), so depth-3 isn't the highest number and I'm guessing that depth-2 may not have files so it doesn't exist, for example.

Post Reply