How To Read A Man File

I have a similar problem that i can’t get my head around. I have a folder that contains a number of sub folders. Each sub folder contains a number of .txt files. I need a batch file to concatenate the files in each sub folder. Here is an example of the file tree: topfolder/topfolder/subfolder1/topfolder/subfolder1/text1.txttopfolder/subfolder1/text2.txttopfolder/subfolder1/text3.txttopfolder/subfolder2/topfolder/subfolder2/text1.txttopfolder/subfolder2/text2.txttopfolder/subfolder2/text3.txtI need the script to output one file per sub-folder:topfolder/subfolder1/concat.txttopfolder/subfolder2/concat.txtSo far i have worked out how to concatenate files in a directory using:FOR %f IN (*.txt) DO TYPE “%f” >> concat.txtand recursively move thru the directory tree using something like:FOR /R %filLoc% %x IN (.) DO <> %xBut when i try to combine the two concat.txt reports either the file name or complains about ‘system cannon find the path specified’. I’m new to programming and any help would be greatly appreciated. Especially some example code 😀 Thanks,Mandy. I think that is because when you are looping, the %f only stores the filename, so it doesn’t know the directory name.You’ll need to include the directory name in as part of your filename or do a change directory (“cd”) command before you do your concatenation. Mandy you need to adjust the paths so they actually match. If you will be using this from the command line instead of a batch use a single percent symbol.for /f “delims=” %%a in (‘dir/b C:topfoldersubfolder1*.txt’) do type %%a >> “C:topfoldersubfolder1concat.txt”for /f “delims=” %%a in (‘dir/b C:topfoldersubfolder2*.txt’) do type %%a >> “C:topfoldersubfolder2concat.txt”. I had to read the help for “for” about 7 times but i finally figured out adding the tokens option with an asterisk will capture long filenames with spacesexample:for /f “tokens=*” %%A IN (‘dir /b *.txt’) do whatevermaybe there’s a better way, but this is the first and only solution i’ve figured out…. Hello jim,I’m having some trouble with some batch I made based on this post.PLEEEEEASE HELP!!here goes the batch———————————-javac %1for /f %%a IN (“%1″) do echo “”>%1.htmlpause————————————it works fine when called from commandline,however when I try to drag and drop files in windows explorer it gets weirdas you can see it gets a java file,compiles it into a class file and creates an html file to display the appletbut when I try drag and drop,it just substitutes “java”(which is the extension of course) for %%~na instead of the file namehelp!!. I don’t know about dragging and dropping files onto a DOS batch file. You might want to create a test batch file that just echos out the filename or arguments that is passed to it, when you drop a file on it. That way you can debug testing the batch file without having it mixed in with actual real functional coding. how do i call a exe n times in a loopand pass parameter to that exe.I am a begginer with this and this may be a trivial question to the forum users, kindly help.Thanks. Howto:Not screw around for hours trying to get one of these commands to work correctly…Download and use the forfiles command instead. It has options for automatic recursing, file masks and even dates and its free too. is it possible to just read one line at a time and execute it with variable. this is what i used in unix. wonder if dos can do the same thing.for i in `cat file.txt` (read line and assign to variable $i)docommand $idonewill loop till end of line.thanks. Mike, that’s the same problem that nigel commented about. Take a look at the stackoverflow link in my previous comment. Jim,That is very good link indeed.I can very well read first line with my code, which can give me“Name=John”… or if I use “delims==” in my For loop I can retrieve “Name” and store in some variable (Tile in my code). But Is there any way where I can get “John” from my File.txt and store it with in my For loop ? I am working on Batch file first time. I would appreciate if you could send me a link, where I can graduate myself on this.Mike. You can use the DOS name of the file (the name that has the tilde “~” symbol in it) or try to use quotes around the entire path. OK, so this may not be the place to ask this, but it does relate. I am writing a DOS batch file to perform a few different things, which I have successfully created. Now, I would like to modify it so that it can be reusable. I have several variables that I would like to store together in one file. Then, I would like to have the batch file parse that file to get the values to pass on to the variables. Make sense? Can anyone help me? Thanks. In the Past I’ve found it easier using the command shell in W2K and above to just string together variables something like Command line version:for /l %a in (1,1,254) do for /l %b in (1,1,254) do ping 10.%a.10.%b. Raghu,Looks like you’ve already have the batch file written. Just save that command into a text file and change the file extension to .bat. Jim, I saw your example to loop through files. I modified your example thinking I could recursively loop through files and call a program to format some XML request files – in nested subfolders.Here is what I did:for /f %%a IN (’dir /b *.xml’ /s) do call formatXML.exe %%aThis works for the first subfolder but that is it. When it ‘errors’ it appears to be passing the folder name to the ‘formatXML.exe’ as the first paramater – rather than an xml file. Do you know how I can get around this?Thanks.Jeff. Jeff, I think it’s because you have the /s flag which is including subdirectories. I think you need to move that next to the /b flag of the dir command rather than outside of the quoted command. Jim, you are correct that my syntax was incorrect. When I changed the batch code to the following:for /f %%a IN (‘dir /b /s *.xml’) do call formatXML.exe %%aI am still receiving the same problem as described above. Seems I get through the first folder (formating several xml files) then I’m passed a directory/folder name and the formatXML.exe fails.Any idea how I prevent the directory/folder from being passed to my ‘called’ exe?Thanks.Jeff. Jeff, I think you can create two different loops. The first loop would loop through the folder structure. The second loop would go through each file in the directory and call your executable. An alternative would be to find a “dir” command switch that suppresses folder names and include that in your /b /s switches. I need to write a batch fiel that will loop thru a directory structure and execute an executable in each subdirectory. Each subdirectory had the same name just incremented by one digit. That is sub1, sub2, sub3.Thanks. This method of grabbing all the files in a dir and doing something to each is just what I was looking for. I was trying to do everything in the first(single) file with no luck.Thanks for sharing. Please could someone help me?I’m trying to delete all files but the first 31 of a “prova” directory (delete the 32th, 33th, 34th, etc…)I used this command in the XP prompt and works:for /F “tokens=* skip=31 delims=” %a in (‘dir /B /N /ON “C:Documents and Settingsuel1421DesktopSalvataggioprova”‘) do del prova%aCopying it into a .bat file doesn’t work… Why????(notice that the .bat file is in “C:Documents and Settingsuel1421DesktopSalvataggio” so “prova” directory should be found when running the .bat)Can’t see the error either putting a pause after the command, the prompt opens and suddenly closes without letting me read the error.Also tried replacing %a with %a%, %%a, %var%, %%var, %var but doesn’t work.And also tried cd “C:Documents and Settingsuel1421DesktopSalvataggio” before the command but doesn’t work.Thank you for helping me.A. G. Hi,Please help me with the batch file command.I am trying to convert the files from one format to another format. (i.e from .txt to .pdf) .ox.exe is my executable file. and it will except an o/p file name. (so, how to append that info?)And i want the o/p file names to be of the same input file names except with the extensions.i.e 1.txt –> 1.pdf2.txt –> 2.pdf etc…for /f %%a IN (‘dir /b *.txt’) do call ox.exe %%aI tried the above command, but i don’t know the later half of the output.SO, Guys, please help me out. Try something like this:for /f %%a IN (’dir /b *.txt’) do call ox.exe %%a %%~na.pdfThe %%~na is the filename without the extension (so just 1, 2, etc.). I’m working on a batch file that calls a program to watermark photos. Using the basic: for /f “tokens=*” %%a IN (‘dir /b *.jpg’) do echo %%a | call runner.bat “%%a”This works great, until I run into a filename with a “^” in it. With a file called “noah^s art.jpg”, the “runner.bat” file: echo %1“P:Program FilesImageMagick-6.5.7-3composite.exe” -gravity southeast “copyw.bmp” %1 xxx%1returns:echo noah^^s art.jpgOf course, ImageMagick yells at me because there’s no such file as “noah^^s art.jpg”I have no idea why it’s duplicating the ^ character. Putting an echo in the “doit.bat” file returns the correct “noah^s art.jpg” Other tested special characters: [ ] ( ) – _ all worked ok.Any ideas? Not only to figure out the ^, but also what other special characters might be affected so I can test everything before running this on 20,000 photos.Thanks. Can how to read a man file you use the switch on /dir to output DOS 8.3 (shortened) filenames and use those names? I think the 8.3 filenames won’t use special characters (other than the tilde ~). I can’t do that because I code the filename with the date, photo number, and one or two word description. I’d rather stop using the evil characters. (If worse comes to worse I can run a batch rename to replace the ^ with a temporary character, run this batch file, then run another rename to put the ^ back. It’s not like I’m going to do this more than once – I hope!). I’m not asking you to change your file names. All files are stored using the 8.3 name and the longer names are displayed by the OS. You can use the hidden (real) 8.3 filenames by adding a switch to the dir command. You can access the file by it’s 8.3 or long names, it’s still the same file. The filename is just a reference pointer to the place on the disk.If you do a “dir /x”, then you’ll see both the short (8.3) and long filenames. You need to somehow combine that switch with the “/b” switch, but I don’t see an easy way. Otherwise, you’ll need to use “dir /x” and parse out the filenames from the list of information. Hmmm. Interesting. I figured if I used the 8.3 filename and saved it using the 8.3 filename, the system would assume I wanted the file renamed to the short filename and discard the long one. I’ll give it a try – that would be the best solution if it worked. I’ll let you know. I tested it using dir /x tokens=5 to get the short filename and it worked ok, except that the short filename was “noah^s.jpg”, still with the ^ and it came over to runner.bat as NOAH^^S.JPG. HelloI want to create batch file that output should be get all file names from a specified folder to a text file or a excel fileThanks in advance. What if the file in directory is having spaces in their name. Thenfor /f %%a IN (‘dir /b’) do call echo %%ajust prints first word of filename. How can i get full file name?Thanks,-anudeep. I need to convert result.xml files to result.html file using a java plugins. I’m able to do so using command prompt.My problem is that i have many result.xml file in many subfolder. Example,c:projectc:project1result.xmlc:project2noresult.xmlc:project3result.xmlI have tried using the FOR command but i failed.for /r %%1 in (result.xml) do (convertxmltohtml). I have a directory tree that is on a student information system server. Each student has a designated folder inside this tree the path is something like this.student01111 Inside the innermost folder is one file called ph.jpeg, which is the student’s picture. I need to make a copy of that picture in the same directory and call it thumb_ph.jpeg in order for the student’s picture to show up as a thumbnail on other pages in the system. The problem is, on the second tier of the tree there are 100 folders (00 – 99) and inside each of those are a bunch of student folders. I have figured out how to recurse through the tree and make a copy of each file, but the copy is always created in the root directory where the batch is located. So it writes the thumb_jpeg file in the same directory over and over until it loops through every folder.I have something like this…for /r %%f in (*.jpeg) do (copy ph.jpeg thumb_ph.jpegfor /r %%g in (*.jpeg) do (copy ph.jpeg thumb_ph.jpegfor /r %%h in (*.jpeg) do (copy ph.jpeg thumb_ph.jpeg)))Any ideas anyone?. I just want to create a batch file that will take the current date and create a directory using the date. However, ‘/’ is not a valid character in a directory name. So how do I replace the ‘/’ with ‘-‘?ex: dave=%date%echo %dave% :: It give me the date.:: What do I do here to get rid of the ‘/’?Thanks!. Jason,did you try looking at something like this?for /f %%a in (“dir /b /s /ad”) do copy %%aph.jpeg %%athumb_ph.jpegIt should recurse the directories giving only a list of directories and copy the file. I’m brand new to batch files, but i have a problem where i need to run through a specific folder and all its subfolders. This is what i have alreadyfor /R D:NewTest %%a in (“*.wmv”) do asfbin -i “%%a” -o “Reindexed-%%~na.asf” -forceindexNow this works, although the output is in D:NewTest and i would rather have it in the same directory as the original file.So how do i get a variable for the current directory i can use?Oh and happy new years. I knew this was possible, but it has been a while since I have programmed in DOS. But I find it so useful at times, so when I needed a refresher, this article came up first. Thanks, it’s great to see that such a convenient and simple, yet versatile “programming language” is still in use!.