| 1. |
Solve : simple batch file needs little modding? |
|
Answer» Hi there I need to create a batch file that will read a text document and create a file for each line of text I have one that almost works but the trouble is the lines of texts have spaces in them and it is creating a file for each section of text so if i have a line of text that reads 'I want only one file' it will create files called I, want, only, one and file the script I am using is Try:HEY! That was my 3000th post!!! Anyway, BC, wouldn't "tokens=*" and "delims=" pretty much do the same thing?C:\batch>TYPE wonker.bat Code: [Select]echo off setlocal enabledelayedexpansion for /f "delims=" %%i in (file.txt) do ( echo %%i set newf=%%i echo Turn off > "!newf!.txt" dir "!newf!.txt" ) Output: C:\batch> wonker.bat wonker Volume in drive C has no label. Volume Serial Number is F4A3-D6B3 Directory of C:\batch 03/10/2010 05:28 PM 11 wonker.txt 1 File(s) 11 bytes 0 Dir(s) 298,567,569,408 bytes free hope Volume in drive C has no label. Volume Serial Number is F4A3-D6B3 Directory of C:\batch 03/10/2010 05:28 PM 11 hope.txt 1 File(s) 11 bytes 0 Dir(s) 298,567,569,408 bytes free works Volume in drive C has no label. Volume Serial Number is F4A3-D6B3 Directory of C:\batch 03/10/2010 05:28 PM 11 works.txt 1 File(s) 11 bytes 0 Dir(s) 298,567,569,408 bytes free C:\batch> Input: C:\batch>type file.txt wonker hope works C:\batch>thanks to all who replied from all your suggestions I tried the easiest looking one first and with a little modding got it working perfect I ended up using for /f "tokens=*" %%i in (file.txt) do echo off> %%i not that its that important for me at the moment but I have in past wanted to do same thing but to MAKE folders instead of files but used to have same problem with it creating new folder for each word so thought Id SEE if this would now work same for folders so I tried for /f "tokens=*" %%i in (file.txt) do mkdir %%i but this still made the folders for each word any ideas why that is? Wrap it in quotes. Like this: "%%i"brilliant had tried similar when trying to mod my original script for making files which DIDNT work so didnt try doing same again, but it worked on that one thanks so much for all your help this forum is great, get plenty of quick succesful responses. I'm just beginning with trying to learn some basics with making scripts and have got a few ideas of scripts I would like to create so no doubt you will here from me again within the next few days. thanks again, James. |
|