Click here for important information about

Solved Simple batch command to copy few files

May 22, 2020 at 05:51:25
Specs: Windows 10
Hello, I don't have any experience in programming and I'm trying to create a simple .bat file for my work which I would put in a directory I want, and it would copy all the files with certain extensions + one more file (which always has the same name) from the directory I put the .bat file in, to a newly created folder in the same directory (or on the desktop doesn't really matter).

I've spent few hours trying to learn batch commands I need and writing this script but without much luck. As i understand, I need to use Xcopy command for copying, then %~dp0 to select the current directory (where .bat file is in) then list the extensions I need to be copied which are ._cad.stl *.constructionInfo *.dentalProject * preview.png (this one is optional i could do without it if it's more complicated) and then use mkdir command to create a new directory, but i'm not sure how to make it work and put it all together, any help would be extremely appreciated, thanks big time guys ...

See More: Simple batch command to copy few files

May 22, 2020 at 06:21:33
I recommend start learning powershell.

Try this in powershell:

Get-ChildItem -Path "C:\folder" -Include "*.txt*", "*filename*" | Copy-Item -Destination "C:\folder-destination"

I prefer powershell as i feel it explains it self a bit more/is more logical than batch when looking at it.
Theres also a lot more you can do in powershell that you cant do in batch, like install modules to connect to outlook, manage windows updates etc etc...

As for making new folders you can look into "New-Item"
In powershell you can f.eks do: Get-Help -Name New-Item -Examples
But theres also a lot of documentation online:

If you have any question about powershell, just post them here or PM me.

If you want to make a script, save it as .ps1 and run with powershell.

message edited by Kilavila

Report •

May 22, 2020 at 16:22:38
✔ Best Answer
Change the pushd so it goes to where your files are.

::====== script starts here =================
@echo off & setLocal enableDELAYedeXpansioN
pushd d:\MyFiles

for /f "tokens=* delims= " %%a in ('wmic os get localdatetime ^| find "20"') do (
set D=%%a & set F=!D:~0,14!
md !F!

> %TEMP%\filelist.txt dir/b *.txt *.bat mycat.jpg

for /f "tokens=* delims= " %%i in (%TEMP%\filelist.txt) do (
copy "%%i" !F!\ > nul
goto :eof
::====== script ends here =================



Report •

May 25, 2020 at 01:47:11
thanks guys you are the best!!!! The script is working very well! Couldn't have done this myself, batch scripts are bit too complicated for me! I'll try to learn some powershell for the future :)

Report •
Related Solutions

Ask Question