copy

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
key
Posts: 11
Joined: 23 Oct 2022 23:36

copy

#1 Post by key » 05 Dec 2022 00:47

1. batch file name as folder name
2. need to copy multiple extensions files copy to another path
3. need to subfolder and inside file only copy to another path

miskox
Posts: 626
Joined: 28 Jun 2010 03:46

Re: copy

#2 Post by miskox » 05 Dec 2022 01:46

viewtopic.php?f=3&t=6108

Maybe you could do this:

Code: Select all

help copy
or

Code: Select all

copy /?
Saso

key
Posts: 11
Joined: 23 Oct 2022 23:36

Re: copy

#3 Post by key » 05 Dec 2022 01:54

@echo off
setlocal enabledelayedexpansion
xcopy /D /U /Y "anyfolder\batch name as folder name\anyfolder\*" "anyfolder\spi-batch name as folder name\anyfolder\"
xcopy /E "anyfolder\batch name as folder name\anyfolder\" "anyfolder\spi-batch name as folder name\anyfolder\"
xcopy /D /U /Y "anyfolder\batch name as folder name\anyfolder\*" "anyfolder\spi-batch name as folder name\anyfolder\"
echo Finished
pause

in need specific multiple extensions and batch file name as the folder name in both source and destination.

miskox
Posts: 626
Joined: 28 Jun 2010 03:46

Re: copy

#4 Post by miskox » 05 Dec 2022 04:53

%0 returns batch name.

Code: Select all

@echo %0
Saso

P.S. Use code tags, please.

key
Posts: 11
Joined: 23 Oct 2022 23:36

Re: copy

#5 Post by key » 05 Dec 2022 05:32

not working

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: copy

#6 Post by atfon » 05 Dec 2022 09:27

key wrote:
05 Dec 2022 05:32
not working
"not working" is not a helpful response. What isn't working? What message do you receive when you issue the commands Saso suggested?

key
Posts: 11
Joined: 23 Oct 2022 23:36

Re: copy

#7 Post by key » 05 Dec 2022 11:31

need to copy specific files extension and copy subfolder with specific files extension

Code: Select all

@echo off
setlocal enabledelayedexpansion
for %%A in (*.bat) do (
   
   for /f "delims=" %%B in ("%%A") do set fname=%%~nB
   for /f "delims=" %%C in ("%%A") do set fextn=%%~xC
   for /f "tokens=1* delims=_" %%D in ("!fname!") do set folname=%%D
   echo folder name [b]!folname![/b]

echo
xcopy /Y "E:\folder1\folder2\[b]!folname![/b]\folder3\" "G:\folder1\folder2\[b]spi-!folname![/b]\folder3" [b](e.g., *.jpg; *.tiff; *.eps)[/b]
xcopy /E /Y "E:\folder1\folder2\[b]!folname![/b]\folder3\" "G:\folder1\folder2\spi-!folname!\folder3" [b](e.g., subfolder)[/b]
xcopy /Y "E:\folder1\folder2\[b]!folname![/b]\folder3\" "G:\folder1\folder2\[b]spi-!folname![/b]\" [b](e.g., *.jpg; *.tiff; *.eps)[/b]
)
echo Finished
pause

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: copy

#8 Post by ShadowThief » 05 Dec 2022 13:07

miskox wrote:
05 Dec 2022 04:53
%0 returns batch name.

Code: Select all

@echo %0
Saso

P.S. Use code tags, please.
%0 returns the entirety of what was typed when the script was called. Presumably they're looking for %~n0.

key
Posts: 11
Joined: 23 Oct 2022 23:36

Re: copy

#9 Post by key » 06 Dec 2022 03:50

Kindly help me pls.

miskox
Posts: 626
Joined: 28 Jun 2010 03:46

Re: copy

#10 Post by miskox » 06 Dec 2022 07:48

What happens if you execute your .bat file? (of course remove BOLD tags)

Code: Select all

@echo off
setlocal enabledelayedexpansion
for %%A in (*.bat) do (
   
   for /f "delims=" %%B in ("%%A") do set fname=%%~nB
   for /f "delims=" %%C in ("%%A") do set fextn=%%~xC
   for /f "tokens=1* delims=_" %%D in ("!fname!") do set folname=%%D
   echo folder name !folname!

echo.
ECHO xcopy /Y "E:\folder1\folder2\!folname!\folder3\" "G:\folder1\folder2\spi-!folname!\folder3\"
ECHO xcopy /E /Y "E:\folder1\folder2\!folname!\folder3\" "G:\folder1\folder2\spi-!folname!\folder3\"
ECHO xcopy /Y "E:\folder1\folder2\!folname!\folder3\" "G:\folder1\folder2\spi-!folname!\"
)
echo Finished
pause
Note I added a dot after the ECHO command.
your notes were not REMed so that would cause problems. Also I added two back slashes in the first two XCOPY commands.

Do you see the correct command syntax If you run this code? Can you run it in a test enironemnt?

Saso

key
Posts: 11
Joined: 23 Oct 2022 23:36

Re: copy

#11 Post by key » 06 Dec 2022 23:31

need copy with extension (e.g., *.jpg; *.tiff; *.eps) how to include this

key
Posts: 11
Joined: 23 Oct 2022 23:36

Re: copy

#12 Post by key » 06 Dec 2022 23:32

(e.g., *.jpg; *.tiff; *.eps) 2 or more extension at a time

miskox
Posts: 626
Joined: 28 Jun 2010 03:46

Re: copy

#13 Post by miskox » 07 Dec 2022 00:24

Let me give you this link again: viewtopic.php?f=3&t=6108

We are all wasting our time because your original post does not (and additional posts) provide enough information. You would probably already have a solution if your original post had all the information required:

You wanted to know

"1. batch file name as folder name"

and I gave you the answer to use %0. And then it turns out that you want to process the list of all the *.bat files in the [current] directory. And for that you need something else.
need copy with extension (e.g., *.jpg; *.tiff; *.eps) how to include this
Maybe you could provide extensions in a list - never tried that (I don't use XCOPY) - so you could duplicate XCOPY commands for this. In short something like this:

Code: Select all

REM modify your XCOPY command of course
XCOPY *.jpg  outfolder\
XCOPY *.tiff outfolder\
XCOPY *.eps  outfolder\
Saso

Post Reply