Page 1 of 1

copy

Posted: 05 Dec 2022 00:47
by key
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

Re: copy

Posted: 05 Dec 2022 01:46
by miskox
viewtopic.php?f=3&t=6108

Maybe you could do this:

Code: Select all

help copy
or

Code: Select all

copy /?
Saso

Re: copy

Posted: 05 Dec 2022 01:54
by key
@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.

Re: copy

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

Code: Select all

@echo %0
Saso

P.S. Use code tags, please.

Re: copy

Posted: 05 Dec 2022 05:32
by key
not working

Re: copy

Posted: 05 Dec 2022 09:27
by atfon
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?

Re: copy

Posted: 05 Dec 2022 11:31
by key
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

Re: copy

Posted: 05 Dec 2022 13:07
by ShadowThief
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.

Re: copy

Posted: 06 Dec 2022 03:50
by key
Kindly help me pls.

Re: copy

Posted: 06 Dec 2022 07:48
by miskox
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

Re: copy

Posted: 06 Dec 2022 23:31
by key
need copy with extension (e.g., *.jpg; *.tiff; *.eps) how to include this

Re: copy

Posted: 06 Dec 2022 23:32
by key
(e.g., *.jpg; *.tiff; *.eps) 2 or more extension at a time

Re: copy

Posted: 07 Dec 2022 00:24
by miskox
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