Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   Create a new batch file (http://www.programmingforums.org/showthread.php?t=9384)

Steiner Apr 15th, 2006 11:59 PM

Create a new batch file
 
Does anyone know how to make a .bat file that will create another .bat file to a specific directory and run a command when opened? Does any one have any ideas? Thanks

InfoGeek Apr 16th, 2006 12:28 AM

:

touch /some/dir/newfile
echo ls>>/some/dir/newfile
chmod 700 /some/dir/newfile


Steiner Apr 16th, 2006 2:22 AM

Maybe I'm jsut retarded here but no matter what I put in "dir" or anywhere I can't get the new file to be created in anything but "C:\" and I want it in "C:\Documents and Settings"

OpenLoop Apr 16th, 2006 8:31 AM

@infogeek: I think Steiner is talking windows, not linux.

@steiner: Open a batch file, say 1.bat and put
:

echo some command >c:\docume~1\file2.bat

If you want to append to the file every time you run 1.bat, use
:

echo some command >>c:\docume~1\file2.bat

Steiner Apr 16th, 2006 11:12 PM

thanks alot I'll specify Windows next time, sorry about that

PhilBon Apr 17th, 2006 5:12 PM

What you might want to do is include the whole path c:\dir\me.bat or do cd dir then create it.

OpenLoop Apr 17th, 2006 9:59 PM

Quote:

Originally Posted by PhilBon
What you might want to do is include the whole path c:\dir\me.bat or do cd dir then create it.

you mean like this
:

echo some command >>c:\docume~1\file2.bat

mackenga Jul 12th, 2006 5:20 PM

Just an aside, if you don't like the artificially shortened version of the directory name, you can actually use spaces in filenames on the command line in recent versions of Windows by surrounding the filename with quotes, like:

:

echo some command >> "C:\Documents and Settings\file2.bat"

I haven't tested this (don't have a Windows machine) but it should work. Just remember the quotes have to go around the whole path, not just the parts of it that wouldn't work without them. This works for long filenames and filenames with 'invalid' characters. Off the top of my head, I'm not sure how you include a quote in this; I'd expect doubling up the quotes would do. You probably won't have to do this anyway but I think:

:

C:\> echo test > "file with ""quotes"" in name"

should create a file called

:

file with "quotes" in name

It might not, but doubling up otherwise invalid characters in strings is usually the way to deal with them on Windows.

Hope this helps.


All times are GMT -5. The time now is 4:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC