Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.




85 posts

Master Geek


Topic # 53850 14-Dec-2009 14:12
Send private message

Hi guys long story short why doesn't this work?



C:\>echo sddsfsdfd > "%date%.txt"
The system cannot find the path specified.


If I use:


C:\>echo sddsfsdfd > %date%.txt


It works but because %date% = Mon 14/12/2009 (and there is a space between Mon and 14)


It will save the file as just Mon.txt






How do I get it to save as Mon 14/12/2009.txt???

Create new topic
3251 posts

Uber Geek
+1 received by user: 207

Trusted

  Reply # 282331 14-Dec-2009 15:06
Send private message

It might be because the filename can't contain "/"?

187 posts

Master Geek


  Reply # 282337 14-Dec-2009 15:24
Send private message

try the following:
Set FileDate=%date:/=%
C:\>echo sddsfsdfd > %FileDate%.txt

Set FileDate=%date:/=%
Strips the "/" from the date.

Set FileDate=%date:/=-%
Will swap the "/" for "-"


 
 
 
 


3251 posts

Uber Geek
+1 received by user: 207

Trusted

  Reply # 282342 14-Dec-2009 15:30
Send private message

Or if you change the short date separator from "/" to "-", it will work too.

615 posts

Ultimate Geek
+1 received by user: 72

Subscriber

  Reply # 282346 14-Dec-2009 15:40
Send private message

You can also break up the date output into separate tokens with a FOR command, eg:

for /F "tokens=1-2 usebackq delims== " %%f in ('%date:/=%') do set a=%%g.txt
echo Testing > %a%

would give you filename something like 14122009.txt
Otherwise you still have the "Mon.txt" problem.
If you want the "Mon" included just change the set command to include "%%f".



85 posts

Master Geek


  Reply # 282400 14-Dec-2009 17:41
Send private message

awesome cheers guys that works, kind of feel like an idiot now :-)



85 posts

Master Geek


  Reply # 282441 14-Dec-2009 19:08
Send private message

hmm I'm trying to fix %time% up now :D

How would I write a for loop like the one lurker did above to change the way %time% displays

C:\Users\james>echo %time%
19:07:18.92

I want it in this format 1907


This is as far as I have got but man batch files can be bloody confusing...


for /f "tokens=1,2 delims=:" %%i in ('%time%') do SET time=%%i%%j
echo %time%

615 posts

Ultimate Geek
+1 received by user: 72

Subscriber

  Reply # 282467 14-Dec-2009 20:39
Send private message

You forgot the usebackq parameter, try putting that in between your token & delimiter ones and it should work.

Create new topic



Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:





News »

Vodafone TV — television in the cloud
Posted 17-Oct-2017 19:29


Nokia 8 review: Classy midrange pure Android phone
Posted 16-Oct-2017 07:27


Why carriers might want to embrace Commerce Commission study, MVNOs
Posted 13-Oct-2017 09:42


Fitbit launches Ionic, its health and fitness smartwatch
Posted 12-Oct-2017 15:52


Xero launches machine learning automation to improve coding accuracy for small businesses
Posted 12-Oct-2017 15:45


Bank of New Zealand uses Intel AI to detect financial crime
Posted 12-Oct-2017 15:39


Sony launches Xperia XZ1, a smartphone with real-time 3D capture
Posted 11-Oct-2017 10:26


Notes on Nokia’s phone comeback
Posted 10-Oct-2017 10:06


Air New Zealand begins Inflight Wi-Fi rollout
Posted 9-Oct-2017 20:16


The latest mobile phones in perspective
Posted 9-Oct-2017 18:34


Review: Acronis True Image 2018 — serious backup
Posted 8-Oct-2017 11:22


Lenovo launches ThinkPad Anniversary Edition 25
Posted 7-Oct-2017 23:16


Less fone, more tech as Vodafone gets brand make-over
Posted 6-Oct-2017 08:16


API Talent Achieves AWS MSP Partner Status
Posted 5-Oct-2017 21:20


Stellar Consulting Group now a Domo Partner
Posted 5-Oct-2017 21:03



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.