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.
Related
This question already has answers here:
Delete file with specific extension in batch file
(3 answers)
Closed 2 years ago.
I have .blk and .blkx files in the same folders, of wich im trying to delete only the .blk file. Ive attempted examples found on this post as in del "\folder\*.blk" /s. I managed to get the chosen files deleted however the .blkx files were deleted too (other files werent so i assume its an issue with both the file having .blk in their extension).
How can i select only the .blk file?
Edit: I dont know why this post was marked a duplicate but the above pinned post does not resolve the problem (wich i already talked about not working)
You must have SFNs (short filenames) enabled on that drive, and the .blkx extension is mapped to .blk in the short 8.3 filename. Because of this, and because wildcards match both long and short names, *.blk returns both .blk and blkx files. To distinguish between them you'll need to run a for loop, check the actual extension, and delete each .blk individually.
for %%b in (*.blk) do #(if /I "%%~xb" == ".blk" echo del "%%~b")
Remove echo from the above to actually delete the .blk files.
To recurse into subdirectories (like del /s) use for /r instead of for.
The command is written as to be used in a batch file (per the question tag). To run it at a command prompt, instead, replace the double percents %%b with single ones %b.
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?
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.
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!
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