0

i have created a script and wanna it to loop through all the file in a directory.. but i failed to do that.. i create another script to apply the script (change_content).. here the code,

cd \input

for %%f in (*.txt) do (

            echo "%%~nf"
            "D:\deployment code\change_content" .\"%%~nf".txt
    )

change_content.bat

call :yesterday today -1
for /f "delims=" %%a in (%1) do (
set "val=%%a"
if "!val:~12,10!"=="0001-01-01" (
>> D:\temp\%1_changed.txt echo !val:~0,12!%day%!val:~22!
) else (
>> D:\temp\%1_changed.txtecho %%a     
)
)

My problem is i cant let the script to read the input file if i put it as variable. I can only put the actual file which not helpful in automate the process? this is just part of the code where i point to the input and output direction.. just wondering what should i do at the for /f place..

Would be appreciate if anyone could help on this..thanks :)

1
  • install Cygwin. Use bash. You'll be happier... Commented Jul 23, 2012 at 2:02

1 Answer 1

1

I understand your problem as what you listed in bold text above. The following should work, going from memory, but I cannot test it now as I am without a Windows computer now ( and happy I don't have to have one with me ).

If you are instersted in the main program looping portion, try this:

setlocal eneabledelayedexpansion

REM:: take \input as param from command line
set top_folder=%~1
set change_content="D:\deployment code\change_content.bat"

for /f "eol=; tokens=1 delims=" %%t in ( 'dir /b !top_folder!\*.txt' ) do (
  REM:: the /b may or may not give yo the full path you need
  REM:: google this if I am wrong

  set file_name=%%~nt
  !change_content! !file_name!

)

If you are interested in the change_content portion, try this:

setlocal enabledelayedexpansion

REM:: change_content looping over file_name variable.
set file_name=%~1
for /f "eol=; tokens=1 delims=" %%f in ( 'type "!file_name!"' ) do (
  set line=%%f
  REM::  Do your thang in here with !line!.
) 
Sign up to request clarification or add additional context in comments.

2 Comments

Lemme know if what I added after your last comment is not necessary and I can revert the answer to what it was when you accepted. ( I didn't see the accept until after I submitted the last edit ). Thanks :)
hhmm.. in fact i can work with type !file_name! the rest i didn't try.. anyway still working fine :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.