Make a folder with today's date with a batch file [duplicate] - batch-file

This question already has answers here:
How do I get current date/time on the Windows command line in a suitable format for usage in a file/folder name?
(30 answers)
Closed 7 years ago.
I am fairly new with creating batch files.
I have made a batch file with the following content:
"C:\Program Files (x86)\Runtime Software\DriveImage XML\dixml.exe" /bC /c /l /t"B:\DRIVE IMAGES\Windows10_maintenance_backup
This allows me to run DriveImage XML and take a backup simply by running the bat file.
I would like the bat file to automatically make a folder with today's date so that:
B:\DRIVE IMAGES\Windows10_maintenance_backup
Becomes:
B:\DRIVE IMAGES\2016.01.20\Windows10_maintenance_backup
How can I achieve this by editing the .bat file?
I have had a look at foxidrives solution here but I do not know how to implement the solution.

echo md B:\DRIVE IMAGES\%date:~-4%.%date:~7,2%.%date:~4,2%\windows10\etc
See set /? for help on substring extraction.
This assumes date is in following format
Thu 21/01/2016

Related

How to paste in the command line (not using shortcuts/mouse)? [duplicate]

This question already has answers here:
How can you get the clipboard contents with a Windows command?
(14 answers)
Access clipboard in Windows batch file
(11 answers)
Closed 2 years ago.
I am working on a batch script that runs .exe files in a given folder. It should do something like this:
SET /P _inputname= Please enter app folder path:
cd %_inputname%
dir /s /b *.exe | clip
"paste-from-clipboard"
However, for my last line, I haven't found a way to paste from clipboard without using a mouse/keyboard shortcut. I would greatly appreciate it if anyone has a solution.
To copy & paste within windows command line you can use:
https://github.com/kpym/windows-paste
It's the successor of the once famous paste.exe.
See also How can you get the clipboard contents with a Windows command?

How to create folder with date and time using timestamp with robocopy command [duplicate]

This question already has answers here:
How do I get current date/time on the Windows command line in a suitable format for usage in a file/folder name?
(30 answers)
Closed 2 years ago.
I want to create a folder using this Timestamp: %DATE:/=-%_%TIME::=-%
My Robocopy command is :
ROBOCOPY "%BUILD_SOURCESDIRECTORY%\sourcefolder\" "\\server\destination\%date:/=-%_%time::=-%" /V
but it is not working, getting an error:
2020-04-07T03:53:21.7269608Z ##[error]Process completed with exit code 1.
2020-04-07T03:53:21.7292925Z ##[debug]System.Exception: Process completed with exit code 1.
at Microsoft.VisualStudio.Services.Agent.Worker.Handlers.ProcessHandler.RunAsync()
at Microsoft.VisualStudio.Services.Agent.Worker.TaskRunner.RunAsync()
at Microsoft.VisualStudio.Services.Agent.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
Note:
I referred to the below link but I want to create a folder with date and time.in this link only date stamp mentioned.
How to use Robocopy to copy files with TimeStamp in command line
if anyone has an idea about, please let me know.
Here's a single line for your batch file, which should do as you need.
Please note that when you input your real source path, spell it correctly, (sourcefolder, not sorcefolder), and ensure that it doesn't have a trailing backslash. The same is true for your destination.
#For /F "Tokens=1-6Delims=/: " %%G In ('""%__AppDir__%Robocopy.exe" \: . /NJH /L|"%__AppDir__%find.exe" " 123""')Do #"%__AppDir__%Robocopy.exe" "%BUILD_SOURCESDIRECTORY%\sourcefolder" "\\server\destination\%%G-%%H-%%I_%%J-%%K-%%L" /V
Obviously, the server path must be mounted/available and the user must have the required permissions for the task too.
Use the Publish Build Artifacts task to publish build artifacts. Use the Windows Machine File Copy task to copy files to a remote Windows machine.
There is no reason to manually copy files with Robocopy.

How do I make a self locating batch file [duplicate]

This question already has answers here:
Get current batchfile directory
(4 answers)
Closed 3 years ago.
So basicly I want to make a batch file that can execute other files, while learing its own location on execution.
It should then use it own path as a reference to the other files.
How should I go about coding that or are there any guides for exactly that?
Thanks in advance!
The batch file name as entered via command line is stored in %0. Using file expander to get other parts. You can put the following code into a batch file and try it out:
REM print batch filename as user entered
echo %0
REM print full file name: d - drive, p - path, f - filename
echo %~dpf0
REM print path only
echo %~dp0
The current directory is stored in %CD%, in case you need it.

How to run Diskpart in batch file? [duplicate]

This question already has answers here:
How do I minimize the command prompt from my bat file
(14 answers)
Closed 6 years ago.
I have Created Text file where it contains dispart commands and I run it from
The Batch File using the code below:
#echo off
Diskpart.exe /s D:\script.txt
Hopefully, That's works fine but there is something I don't want it to happen anymore and that was when Dispart.exe opened.It is openning maximized.
So how to make it openning minimized?
Use this command in your .bat file:
start /min diskpart
Hope this helps. Good luck!

deleting files older than 30 days with a .bat fle [duplicate]

This question already has answers here:
Batch file to delete files older than N days
(25 answers)
Closed 6 years ago.
I am tring to write a .bat file to delete files older then 30 days in a specific folder I have tried several diifrent format with no luck.
the closest one i got is
del C:\temp\temp d -30
edit.....
ok so i got forfilles /p c:\temp\temp /d
how can I make it use the date when its ran instead of always having to go in and change it evrytime I run it and get them to delete them now
can any one help me out
thanks
There is no such switch available to the DELete command. Type FORFILES /? into a console window, read the output taking special note of the /D parameter.

Resources