Batch robocopy pdf files created today - batch-file

i want to copy pdf files created today incl. their path to a
destination folder. I tried robocopy but even i use /S as parameter
folders without any content getting copied.
Here is my script:
robocopy "h:\origin\" "G:\destination" *.pdf /B /S /mt:4 /eta /XA:H /XD "H:\origin\tmp" /l /LOG:sync.log
thanks for your help

Related

Create a Batch file to back up the folders and within that how to exclude one of the folder for back up

I have created a Batch File that will back up all the folders and its subfolders using XCopy. Below is the code: I already have a script that gets the current date and time. I am setting it to curr_date and curr_time.
#echo off
Xcopy /S /I /E /H D:\WorkingTFS\TEST_COP D:\BackUp\%curr_date%_%curr_time%_backup
pause
Now it is backing up all the folders correctly. Now I want to exclude one of the folder (For example: OldTest folder that exists in D:\WorkingTFS\TEST_COP) while creating backup. Can anyone help me in doing this
why not just use EXCLUDE parameter?
#echo off
echo WorkingTFS\TEST_COP\OldTest >exclude.txt
Xcopy /S /I /E /H D:\WorkingTFS\TEST_COP D:\BackUp\%curr_date%_%curr_time%_backup /EXCLUDE:exclude.txt
pause

Windows rmdir batch to delete FOLDERS but skip files

So i have a dir called c:\user\jdoe\desktop\Folder1\
Inside folder1 i have many folders with subfolder and files.
I have a 7-Zip batch that zips all the folders in place.
So now i have subfolders and subfolders.zip inside folder1.
I need a batch that will detele all the non zipped folders but skip the zip files and the .bat file that lives in c:\user\jdoe\desktop\Folder1\
Any ideas?
If i can get a 7-zip batch that will zip fodlers (example subfolder1.zip subfolder2.zip) and then afterwards delete all non zipped folders that would be great.
Been all over the internet and after deleting half my data by testing my own scripts i have now decided to come here.
So after a long collaboration with a friend we came up with this.
Tested this and it is working 100%
REM create list of directories
SET cwd="C:\Users\user\Desktop\New folder"
SET date=date /T
CD %cwd%
DIR /AD /B >dirlist.txt
REM Zip contents of each directory
for /f "tokens=*" %%a in (dirlist.txt) do (
"c:\program files\7-zip\7z.exe" a "%%a.zip" "%%a"
del /s /q "%%a"
rmdir /s /q "%%a"
)
del dirlist.txt
pause

Batch Script robocopy exclude files but not in every folder

I am trying to copy contents of the C:\ drive from one computer to a new computer. I am only trying to copy any user files and not system files. This is my code so far.
#echo off
cls
#echo Type the old Computer Name
set /p asset=
#echo.
#echo What is the user's AIU?
set /p useraiu=
robocopy.exe \\%asset%\c$\ C:\ /S /Z /XJD /XJ /XA:SH /XA:T /XD "Dir1" "Dir2" /XF *.dll *.log *.txt *.exe /log+:"\\server\path\%asset%-to-%computername%-Transfer.log" /NP /FP /V /TEE
I have the exclude Hidden Files, System Files and Temporary Files. I wanted to exclude .dll .log .txt .exe files from the ROOT of C but not from the folders being transferred.
Is it possible to only exculde the files from the Root of C but still transfer them if they exist in the folders?
You could use xcopy
It doesn't copy hidden files or system files. Add the /e parameter to copy empty folders. Add the /c parameter to ignore errors.
xcopy %src% %dest% /exclude:extlist.txt /s
extlist.txt
.dll\
.txt\
.exe\
.log\
.tmp\
EDIT:
Misunderstood your question. Didn't realize you were copying from a networked computer. Xcopy won't work then.

Xcopy - Trying to copy a folder with certain arguments to another location

I'm trying to xcopy certain folders from a directory of 5000 folders, that start with the number 9097*
Approx 2000 folders start with 9097.
for /f %%A in ('DIR /b /a:D') do (
set temp=%%A
set ID=!temp:~0,4!
if !ID!==9097 xcopy *!ID!* F:\%INPUT% /S /i
My problem is that when it finds the first folder starting with 9097, the code then goes and copies all contents of all the folders, I want it to only copy the 9097 folders. I understand why the code above is doing what it is doing but I can't seem to think of the way for it to just copy the folders and contents starting with 9097.
Any advice would be greatly appreciated.
for /d %%a in (9097*) do xcopy "%%~fa" "f:\%input%\%%~nxa" /s /i
For each folder with a name starting with 9097, xcopy from the full path of the source folder to the target inside a folder with the name and extension of the source folder.

Copy only newest folder via batch file

I need to copy over only the latest folder from a folder. All the examples I see online are for copying just the newest file. Is it possible to copy over the latest folder via batch file?
CD folder
FOR /F "USEBACKQ tokens=*" %%A IN (`DIR /A:D /O:-D`) DO (
XCOPY "%%A" "new folder" /E /H /K /Y
GOTO:OUT
)
:OUT
Change directory to the folder in question. Use a FOR loop over the listing of all folders in current folder, arrange them by date with the newest on top, then copy all the contents of that folder to the new destination (/E Copies all directories and subdirectories even if empty, /H include all hidden and system files, /K keeps attribute settings, /Y suppresses the prompt to copy), then leave the loop after the first iteration (i.e. newest file)
Have you tried Robocopy?
Edit to address downvote
robocopy .\src .\dest /e /xo /dcopy:T
Options
/xo
Excludes older files.
/e
Copies subdirectories. Note that this option includes empty directories.
/dcopy:T
Copies directory time stamps.

Resources