Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 15th, 2006, 11:59 PM   #1
Steiner
Newbie
 
Steiner's Avatar
 
Join Date: Jan 2006
Posts: 13
Rep Power: 0 Steiner is on a distinguished road
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
Steiner is offline   Reply With Quote
Old Apr 16th, 2006, 12:28 AM   #2
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
touch /some/dir/newfile
echo ls>>/some/dir/newfile
chmod 700 /some/dir/newfile
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Apr 16th, 2006, 2:22 AM   #3
Steiner
Newbie
 
Steiner's Avatar
 
Join Date: Jan 2006
Posts: 13
Rep Power: 0 Steiner is on a distinguished road
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"
Steiner is offline   Reply With Quote
Old Apr 16th, 2006, 8:31 AM   #4
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
@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
OpenLoop is offline   Reply With Quote
Old Apr 16th, 2006, 11:12 PM   #5
Steiner
Newbie
 
Steiner's Avatar
 
Join Date: Jan 2006
Posts: 13
Rep Power: 0 Steiner is on a distinguished road
thanks alot I'll specify Windows next time, sorry about that
Steiner is offline   Reply With Quote
Old Apr 17th, 2006, 5:12 PM   #6
PhilBon
Hobbyist Programmer
 
PhilBon's Avatar
 
Join Date: Nov 2005
Posts: 172
Rep Power: 3 PhilBon is on a distinguished road
Send a message via AIM to PhilBon Send a message via MSN to PhilBon
What you might want to do is include the whole path c:\dir\me.bat or do cd dir then create it.
PhilBon is offline   Reply With Quote
Old Apr 17th, 2006, 9:59 PM   #7
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
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
OpenLoop is offline   Reply With Quote
Old Jul 12th, 2006, 5:20 PM   #8
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
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.
__________________
"I'm not a genius. Why do I have to suffer?"
mackenga is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:00 AM.

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