my batch script
set "Sourcefolder=D:\PurgeScriptExecute\SourceFile"
set "Destfolder=D:\PurgeScriptExecute\DestFile"
set _NoOfDays=30
robocopy /S /MINAGE:%_NoOfDays% "%Sourcefolder%" "%Destfolder%" /E
echo File copied Successful^>^>%Sourcefolder%>>%Destfolder%
This works perfectly but only for files and not the folders inside the source directory .I don't understand why ??
Note
I don't have to move the files and folders . I need to copy them.
Related
I have files in a folder structure on one network drive and need to copy them via batch to another folder structure on a separate network drive.
I have a batch script that copies them from the source to the destination but it only copies them into the top-level, not into the folders.
Ex:
SOURCE
newsletters
|-2016
|-2017
|-2018
DESTINATION
newsletters
|-2016
|-2017
|-2018
My script copies the files inside the SOURCE\newsletters\.. folders but only puts them into DESTINATION\newsletters, not inside the year folders:
#echo off
setlocal EnableDelayedExpansion
for /R %G IN (*.pdf) DO xcopy "%G" "DESTINATION\newsletters"
Figured it out with ROBOCOPY:
robocopy ./ DESTINATION\newsletters\ /E *.pdf
I saw the other links for some solutions but, I need to run the script for every folder under a main one but to give it its original name.
Example:
Main folder
Folder 1
Folder 2
Folder 3
To output (in the same main folder)
Main folder
Folder 1.zip
Folder 2.zip
Folder 3.zip
Thank you in advanced
You'll need zipjs.bat in the same directory as this piece of code:
#echo off
::Alter the line bellow with your parent directory
set "parent_dir=C:\Parrent\"
for /d %%a in ("%parent_dir%\*") do (
call zipjs.bat zipItem -source "%%~fa" -destination "%%~fa.zip" -keep yes -force no
)
I have found a simple solution for this. Suppose you have multiple sub folders to be zipped in a folder. In that case,
1. Download and lnstall 7zip software. Then copy 7z.exe to the particular folder where you want to zip your subfolders.
in a notepad, copy and paste the following and save as .bat file. :
cd "your_MainFolder_path"
for /d %%f in do (7z a -t7z %%f.7z "your_mainFolder_path\%%f")
In case you want to keep the zip files and remove the original folders, add this after the for statement :
rd /s /q "your_mainFolder_path\%%f"
I have a folder [C:\Users\name\desktop\New_Folder] with multiple folders and files. e.g.
New_Folder
uuu_folder
abcd_folder
abcd_2_folder
abcd_3_folder
nnn.docx
bbb.xlsx
I managed to "xcopy" all the files and folders in this folder to another folder. But, how can only "xcopy" the folders with only name started with abcd which only abcd_folder, abcd_2_folder and abcd_3_folder have copied?
set A_LOCAL=C:\Users\name\desktop\New_Folder
set B_LOCAL=C:\Users\name\desktop\Archive_Folder
set LIST=abcd
This is working for copying all the files and folders.
xcopy "%A_LOCAL%\*" "%B_LOCAL%\" /E
But this is not working for copying folders with specific subname of the folders?
xcopy "%A_LOCAL%\%LIST%_*" "%B_LOCAL%\" /E
Please help.
I'm often compressing folders of images or other project related documents into separate zip files the current command in a bat file I'm using is.
for /d %%X in (*) do "D:\Program Files\7-Zip\7z.exe" a "%%X.7z" "%%X\"
It automatically places the full contents of all folders separate archive files.
My question is if you double click on any of the archives it first navigates to a a folder of the same name as the archive. Is there a way to make it so it doesn't put have to folder, it just has the contents?
Right now I get
D:\User\1501.7z\1501\ contents
I just want
D:\User\1501.7z\ contents
Second if this is possible can it be set up so that if one of the folders has multiple folders in it all the contents of each folder is placed into just the on directory instead of having a multiple folders in the archive.
Thanks,
Tony
This will set the working directory to the folder that you want to zip up and save the zip file one level up from that directory.
#echo off
for /d %%X in (*) do (
PUSHD "%%X"
"D:\Program Files\7-Zip\7z.exe" a "..\%%X.7z" "*"
POPD
)
I have a folder with many subfolders inside them, the subfolders have random numbers/characters as their name, and they all do have an important file in them. But how do i copy all the files in the source folder and in the subfolders to one folder without copy the folders, in a batchfile?
I use Windows7
This should be all you need.
#echo off
for /r "d:\base\folder" %%a in (*) do copy "%%a" "c:\destination\folder"