Page 1 of 1

Copy files all days

Posted: 29 Oct 2015 10:02
by adidas
Hello,
I need your helps.
I have a folder that i get on that a same file but with different date. For exsample:
bbb-5-21-2015.txt
bbb-5-22-2015.txt
I need that the bat file doing this things: Files that correspond to each day's date copied to a new folder is created with the current date in the following path
C: \ ddd \
For example, if the current date is 21-5-2015, the command will create a folder with current date in
C: \ ddd \
And copied into the file vault came on the same day, following path:
\\ mydomain \ files

Re: Copy files all days

Posted: 25 Jan 2017 11:09
by rodrigolima
Hello adidas,

I have created that script below:

So, I used file signature
Dia_ddmmyyyy_X.txt
Delimiter: _

Extract date(format ddmmyyyy) and check if directory ddmmyyyy exist.
If not creates it and move file into.
Adapt to your purposes.

I hope that helps you.
See you


Code: Select all

@echo off
cls

::Create base file that contains file names
dir /b "Dia_*.txt" > pipeline.txt
:: If dir response displays "FILE NOT FOUND
:: It means that is no file to be moved to directories
:: After that script is going exit
 
:: Loop through pipeline.txt and generate folder to move file
for /f "tokens=1,2,3 delims=_" %%a in (pipeline.txt) do (
   
   if not exist %~dp0%%b (
      md %~dp0%%b >NUL
      move /Y %~dp0%%a_%%b_%%c %~dp0%%b >NUL
   )
)

echo Clear Environment
:: Delete Pipeline.txt
if exist %~dp0pipeline.txt (
del %~dp0pipeline.txt
)

goto:eof

Re: Copy files all days

Posted: 25 Jan 2017 12:19
by rodrigolima
Try this:

Code: Select all

@echo off
cls

:: GENERATION AREA - START
dir /b "bbb*.txt" > pipeline2.txt

for /f "tokens=1,2 delims=." %%a in (pipeline2.txt) do (
echo %%a>>pipeline3.txt
)
del pipeline2.txt

for /f "tokens=1-4 delims=-" %%a in (pipeline3.txt) do (
echo %%b-%%c-%%d>>pipeline4.txt
)

del pipeline3.txt
ren pipeline4.txt pipeline.txt
:: GENERATION AREA - END

:: PROCESS AREA - START
for /f %%a in (%~dp0pipeline.txt) do (
   
   if not exist %~dp0%%a (
      md %~dp0%%a >NUL
      move /Y %~dp0*%%a*.txt %~dp0%%a >NUL
   )
)
:: PROCESS AREA - END

echo Clear Environment
:: Delete Pipeline.txt
if exist %~dp0pipeline.txt (
del %~dp0pipeline.txt
)

goto:eof

Re: Copy files all days

Posted: 25 Jan 2017 13:09
by Compo
I have no idea about the latter part of your question, (vault domain copy), but have taken a guess at your requirements for the first part. The rest is up to you.

This will take all files in the holding folder, "C:\Directory\Sub", and copy them to subfolders in "C:\ddd" (named based from the date in the filename):

Code: Select all

@Echo Off
PushD "C:\Directory\Sub"
For %%A In (?*-?*-?*.txt) Do Call :Sub "%%A"
Timeout -1
Exit/B

:Sub
Set "str=%~n1"
Set "i=1"
SetLocal EnableDelayedExpansion
Set "lev[!i!]=%str:-="&Set/A "i+=1"&Set "lev[!i!]=%"
Set/A "#=i-2"
Set/A "$=i-1"
If Not Exist "C:\ddd\!lev[%$%]!-!lev[%#%]!-!lev[%i%]!\" MD "C:\ddd\!lev[%$%]!-!lev[%#%]!-!lev[%i%]!"
Copy %1 "C:\ddd\!lev[%$%]!-!lev[%#%]!-!lev[%i%]!"
EndLocal