Search todays folder and copy to destination

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
foncesa
Posts: 42
Joined: 12 Sep 2013 00:09

Search todays folder and copy to destination

#1 Post by foncesa » 08 Jul 2022 09:45

Hi,

I want to search source folder for todays date and if it exits then copy a particular folder from it, to shared network destination and extract all the files from it and paste it.

source folder c:/Reports/(todaysdate)
particular folder : softimages
network 192.168.1.130
user xxx
password xxx
destination folder f:\images
copy all files from softimage to f:\images

I have this codes to search for date folder and your expert help is required.

Code: Select all

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%dd%%mm%%yyyy%_FR
echo "%datestamp%"

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Search todays folder and copy to destination

#2 Post by aGerman » 09 Jul 2022 05:30

Maybe something about like that (not tested)

Code: Select all

@echo off &setlocal

for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "datestamp=%dd%%mm%%yyyy%_FR

if not exist "C:\Reports\%datestamp%\softimages" exit /b

net use Z: \\192.168.1.130\F$\images password /user:domain\username 
robocopy "C:\Reports\%datestamp%\softimages" Z: /r:0 /w:0
Update password, domain, and username accordingly (and maybe the drive letter if Z is already used).

Steffen

Post Reply