0

I need to create a .bat file that might be very easy but I am having a real hard time trying to figure out how to do it.

I need a batch that gets all the files *.ui in the current folder, and executes a program passing two arguments to it: that *.ui file name, and the same file name with this two modifications

  • Added ../ in front so the referenced file is in the parent folder
  • Replaced file extension from *.ui to *.py

In pseudo:

for every file *.ui in this folder as file:
    file2 = "../" + replace( file, ".ui", ".py")
    execute python.exe file -o file2

This is the final .bat, but the replacing extensions part is missing:

FOR %i IN (*.ui) DO python -m PyQt4.uic.pyuic %i -o (????)

I have tried the batch replacing (????) with the file name manually and it works. But how can I add ../ and replace .ui to .py?

Thank you!

1 Answer 1

2
FOR %i IN (*.ui) DO python -m PyQt4.uic.pyuic %i -o ..\%~ni.py

see for/?

Sign up to request clarification or add additional context in comments.

4 Comments

Hi, sorry but I don't understand your answer. What do you mean with see for/?. I tried the script and it throws an error. Sorry if this is too newbie for you, but if you could help me with this i would appreciate it very much.
What does for %i in (*.bat) do @echo ..\%~ni.py say? (if you use it in a batchfile, double the %: %%i and ..\%%~ni.py)
This prepends ..` although ../` was requested -- this might cause trouble with Python...?
I don't have phyton. Command repetition is fine: ..\filename.py. Ideas: a) doubling the backslash, b) enclose in quotes: "..\%~ni"

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.