Skip to main content
Topic: Creating a .bat file to convert all files of a folder to NWCTXT. (Read 258 times) previous topic - next topic

Creating a .bat file to convert all files of a folder to NWCTXT.

I'd like to convert all my NWC files to NWCTXT.

For 1 file, I know I can do this with a command like:
"C:\Program Files (x86)\Noteworthy Software\NoteWorthy Composer 2\nwc-conv  "nwc_folder\song.nwc" NWCTXT > "nwctxt_folder\song.nwctxt".

So what I need is a .bat file where I can specify the input and output folder and create a loop to convert every file with .nwc extension from the input folder to a .nwctxt file in the output folder.

But my knowledge of the syntax of .bat files is hidden far away in my memory.

So any help would be appreciated.
Always look on the bright side of life!

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #1
Put something like this in your .bat file:

Code: [Select · Download]
for %%F in (%1\*.nwc) do call :DoIt %%F %2
goto :EOF

:DoIt
echo %1 %2
goto :EOF

Instead of echo %1 %2, do your work there: %1 is the nwc file in the input folder, %2 the output folder. There are ways to create a "naked" filename from %1 ... I'll look them up, but my battery is running low ... so I'm in a hurry ....

H.M.

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #2
This is probably a stupid question and likely not helpful, but I'll ask it and offer a possible solution anyway.

Other than the filename extension, is there any difference between  .nwc and .nwctext files?

If not, there is freeware for bulk renaming.  I use CKRenamer, and I imagine other, newer, programs are readily available.

End of stupid question.  I'll duck now. 

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #3
Not a stupid question. With current versions of NWC, a .nwc file is just a compressed version of the .nwctxt equivalent. Therefore, it's smaller on your hard drive.  There are a number of sites out there for converting NWC to MusicXML or other formats, and some of those sites will only convert .nwctxt format files (i.e. they can't uncompress the .nwc).

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #4
Code: [Select · Download]
for %%i in (*.nwc) do "C:\Programs\NoteWorthy Composer 2\nwc2.exe" -convert "%%i" "%%~dpni.nwctxt"

Edit: N.B. this is for a batch file!
For the command line:
Code: [Select · Download]
for %i in (*.nwc) do "C:\Programs\NoteWorthy Composer 2\nwc2.exe" -convert "%i" "%~dpni.nwctxt"

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #5
Code: [Select · Download]
for %%i in (*.nwc) do "C:\Programs\NoteWorthy Composer 2\nwc2.exe" -convert "%%i" "%%~dpni.nwctxt"

Edit: N.B. this is for a batch file!
For the command line:
Code: [Select · Download]
for %i in (*.nwc) do "C:\Programs\NoteWorthy Composer 2\nwc2.exe" -convert "%i" "%~dpni.nwctxt"

Thanks for the quick answer. I like this solution without any goto (Sory H.M :)) ), but I can't get it right.

I changed it a little bit to include my input folder, to: 
Code: [Select · Download]
for %%i in (C:\Users\gustv\Documents\Music\NWC2\Kaaterliedjes\Testcopies\*.nwc) do "C:\Programs\NoteWorthy Composer 2\nwc2.exe" -convert "%%i" "%%~dpni.nwctxt
But that gave errors "Het systeem kan het opgegeven pad niet vinden.", which means, according to Google translate: "The system cannot find the path specified."
My input folder is correct (I can see all the input files in the echo lines), so maybe I have to specify the output path also, but how?
I don't know what "~dpni" means.
Always look on the bright side of life!

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #6
I think the problem is in the
Quote
"C:\Programs\NoteWorthy Composer 2\nwc2.exe"
In my computer it is "C:\Programmi\......." so I suppose you have it translated to flemish.
All that assuming that you don't have NWC installed elsewere, of course.

Quote
%~f1 - expands %1 to a Fully qualified path name - C:\utils\MyFile.txt
%~d1 - expands %1 to a Drive letter only - C:
%~p1 - expands %1 to a Path only - \utils\
%~n1 - expands %1 to a file Name or, if only a path is present,
       the last folder in that path
%~x1 - expands %1 to a file eXtension only - .txt
%~s1 - changes the meaning of f, n and x to reference the Short name
       (see note below)
%~1  - expand %1 removing any surrounding quotes (")
%~a1 - display the file attributes of %1
%~t1 - display the date/time of %1
%~z1 - display the file size of %1
%~$PATH:1 - search the PATH environment variable and expand %1 to the fully qualified name of the first match found.

The modifiers above can be combined:
%~dp1 - expands %1 to a drive letter and path only
%~nx2 - expands %2 to a file name and extension only

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #7
Thanks, I figured it out!

One thing though: the wildcart *.nwc also selects *.nwctxt files. Not a big problem, but a little annoying.
Always look on the bright side of life!

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #8
BTW: Where do I find the full documentation for nwc2.exe -convert?
Always look on the bright side of life!

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #9
Yes, in Windows, three-letters extension patterns match also longer  filename extensions. What you can do:
Code: [Select · Download]
for /F %i in ('dir /b *.nwc ^| findstr /e .nwc') do ...

Re the "goto EOF:", this is no real goto, but .bat's code for "return".

And my version with CALL and a separate block for the things to do is , I think, helpful if you want to execute more than one command in the loop. This is already helpful for adding some echo's for debugging. There is also a different method with parentheses
Code: [Select · Download]
for /F %i in (...) do (
   cmd1
   cmd2
   ...
)

Here are some links:

https://stackoverflow.com/questions/2423935/windows-command-line-search-for-exact-extension-with-dir
https://www.windows-commandline.com/windows-for-loop-examples/
https://www.informit.com/articles/article.aspx?p=1154761&seqNum=10

H.M.

// Edit: | in for loop needs a ^ in front of it. Aha.

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #10
I tried this in a .bat file:
Code: [Select · Download]
for /F %%i in ('dir /b C:\Users\gustv\Documents\Music\NWC2\Kaaterliedjes\*.nwc | findstr /e .nwc') do (
echo %i
)

Result:
Quote
| was unexpected at this time.
Always look on the bright side of life!

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #11
So it goes :-) Now I tried it myself - this is what works:
Code: [Select · Download]
for /F %%i in ('dir /b/s mymusic\*.nwc ^| findstr /e .nwc') do (
echo %%i
)
There's a caret before the |, and two %% after the echo.

H.M.

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #12
Quote
The nwc-conv.exe command line tool is no longer included with the program. The program now handles this task on its own.

-convert: This option can be used to convert a file from one format to another.
Usage: nwc2.exe -convert "[input-file]" "[output-file]"

Both files are required on the command line and the file extension determines the conversion.
Supported conversions include:
.nwc    -> .nwctxt, .mid, or .info
.nwctxt -> .nwc, .mid, or .info

Conversions to .mid support a "-0" option for type 0 files.
Quote
You can invoke the NWC Lua interpreter by adding a -nwcut switch on the command line:

nwc2 -nwcut [YOURTOOL] < nwcfile.nwctxt > outfile.txt 2> errfile.txt

You must provide the redirects, as the program instance will not automatically attach to your current console session.

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #13
This worked fine
Code: [Select · Download]
cd C:\Program Files (x86)\Noteworthy Software\NoteWorthy Composer 2
for /F "delims=" %%i in ('dir /b C:\Users\gustv\Documents\Music\NWC2\Kaaterliedjes\*.nwc ^| findstr /e .nwc') do (
nwc-conv  "C:\Users\gustv\Documents\Music\NWC2\Kaaterliedjes\%%i" NWCTXT > "C:\Users\gustv\Documents\Music\NWC2\Kaaterliedjes\NWCTXT\%%itxt".
)
Always look on the bright side of life!

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #14
Opagust, are you saying that nwc-conv still works even with the newest (so-to-say  :) ) version of NWC?
It can be possible, since
Quote
nwc-conv just acts as a front end to the nwc2 program.
I can't find nwc-conv.exe anymore in my archives. Could you send me a copy of it?

Edit: Found! It was inside nwc2_UserToolStarter, not in a NWC package.

Re: Creating a .bat file to convert all files of a folder to NWCTXT.

Reply #15
Yes, it still works!
And it puts its output on stdout (a thing I needed once).