0

How to make a folder with name as date_time and copy a specified .bat file into that. I want to use .bat file for above stated functionality.

1 Answers1

0

Try using search because working datestamps and DOS have been around for many years.

Try this:

set "newdirectory=c:\%date:/=-%-%time::=-%"
md "%newdirectory%"

will create something like "Thu 01-15-2015-14-41-19.61" (depending on your local date/time settings)

Had to look up substring replace and found this post https://stackoverflow.com/a/6159108/4317867

-Edit, add explanations.

MD using the system variables %DATE% and %TIME% but replace the invalid characters / and :

Community
  • 1
  • 1
user4317867
  • 2,397
  • 4
  • 31
  • 57
  • There are already %date% and %time% system variables that can be used. Also, the `str=` part is going to break absolutely everything. – SomethingDark Jan 15 '15 at 07:07
  • @user4317867: `set %date% = date /t` ?? Did you try that? – Stephan Jan 15 '15 at 07:56
  • @Stephan I'm not the author of the question and I didn't know about those system variables. I also removed str = in my test batch file and things still work. – user4317867 Jan 15 '15 at 08:01
  • 1
    yes, your `md`line works; because it uses the systemvariables `%date%` and `time%`. Not because, but in spite of the two `set`commands. `set %date% = date /t` is as wrong as it could be made. It sets a variable `15.01.2015` to the string `date /t` – Stephan Jan 15 '15 at 08:07
  • Well that is helpful to me but not so much to the question author. Essentially the command in a batch file can be simply `md "c:\%date:/=-%-%time::=-%"` – user4317867 Jan 15 '15 at 08:22
  • OP will need to use the directory created later in the batch, so you need to set a variable in case the time has changed when the time comes to use the directory hence pulling the same date-time method won't be valid. Quoting in the manner shown ensures trailing spaces are not included in the value assigned. – Magoo Jan 16 '15 at 00:09