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
3280 posts

Uber Geek
+1 received by user: 208

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 "-"


 
 
 
 


Try Wrike: fast, easy, and efficient project collaboration software
3280 posts

Uber Geek
+1 received by user: 208

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.

643 posts

Ultimate Geek
+1 received by user: 96

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%

643 posts

Ultimate Geek
+1 received by user: 96

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 »

Amazon launches the International Shopping Experience in the Amazon Shopping App
Posted 19-Apr-2018 08:38


Spark New Zealand and TVNZ to bring coverage of Rugby World Cup 2019
Posted 16-Apr-2018 06:55


How Google can seize Microsoft Office crown
Posted 14-Apr-2018 11:08


How back office transformation drives IRD efficiency
Posted 12-Apr-2018 21:15


iPod laws in a smartphone world: will we ever get copyright right?
Posted 12-Apr-2018 21:13


Lightbox service using big data and analytics to learn more about customers
Posted 9-Apr-2018 12:11


111 mobile caller location extended to iOS
Posted 6-Apr-2018 13:50


Huawei announces the HUAWEI P20 series
Posted 29-Mar-2018 11:41


Symantec Internet Security Threat Report shows increased endpoint technology risks
Posted 26-Mar-2018 18:29


Spark switches on long-range IoT network across New Zealand
Posted 26-Mar-2018 18:22


Stuff Pix enters streaming video market
Posted 21-Mar-2018 09:18


Windows no longer Microsoft’s main focus
Posted 13-Mar-2018 07:47


Why phone makers are obsessed with cameras
Posted 11-Mar-2018 12:25


New Zealand Adopts International Open Data Charter
Posted 3-Mar-2018 12:48


Shipments tumble as NZ phone upgrades slow
Posted 2-Mar-2018 11:48



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.