I am trying to create a .cmd script to archive my project folders in SharePoint using robocopy. The issue that I am having is that there are many folders in the source dir that I do not want to archive.
#set sourcepath=\\foo\bar\p_*
I prepended my project folders with 'p_' so I could set my source variable to /foo/bar/p_*. This way I would pick up each folder and all of it's files without grabbing all of the other 'non-project' folders. Obviously this did not work.
Is there a way to pull this off without having to build a folder list that I need to manage every time a project folder is added?
Your input is appreciated
You can get the list of directories with a command.
dir /A:D /B /r p_*
Then you can use a FOR loop to start robocopy for each directory.
SETLOCAL
SET SOURCEDIR=\\source\...
SET DESTINATIONDIR=\\dest\...
CD %SOURCEDIR%
FOR /F %%G IN ('dir /A:D /B /r p_*') DO robocopy "%SOURCEDIR%\%%G" "%DESTINATIONDIR%\%%G" /e
Related
The below lines need to copy all the folders from \Reports\Input to
\Deliver\Unidentified\Requests. Input directory contains lot of folders which contains files.
but Below code is not copying.
If I change dir /b /ad *`) then it is copying only the files from the input folder subdirectories files.
How to change this Please help on this. Thanks advance
Struture:
under Report --> Deliver,Input folder is there
under Input folder -- Response 1,2,3... folder which contains files.
CD %AUTOMATEDTESTHTTPDIR%\..\Reports\Input
FOR /F "usebackq tokens=*" %%i IN (`dir /ad *`) DO (
ECHO %%i
CD "%%i"
COPY * ..\..\Deliver\Unidentified\Requests
cd..
)
xcopy /S %AUTOMATEDTESTHTTPDIR%\..\Reports\Input\* %AUTOMATEDTESTHTTPDIR%\..\Deliver\Unidentified\Request\
should work. The /S parameter is for recursively copying the files.
You might not need to use a for-loop at all.
I need to create a batch script that will run all .exe files in a folder. This must include subfolders.
I am running windows 7, and the batch file is stored in the root folder
I have tried several variations with no success. The two main variations are as follows
REM dir *.exe /S /B > tmpFile
REM set /p listVar= < tmpFile
REM del tmpFile
FOR %%F IN (%listVar%) DO %%F
=======================================
FOR /F "usebackq" %%F IN ('dir *.exe /S /B') DO %%F
I have looked through several variations on the above methods but none work. The top version (which I would like to avoid) only reads in one line from the file. The Bottom version outputs an unmodified "dir" command in the prompt window.
Ultimately I would like help identifying how to solve this issue without the need for a temp file.
for /r "." %%a in (*.exe) do start "" "%%~fa"
This will start all the executable files under the current folder and subfolders. Change the reference to the current folder (".") to your needs.
for %1 in (%USERPROFILE%\*.exe) do "%1"
This will start all executables in your user folder. Of course, that includes installers and stuff like that, and you probably don't want to reinstall all your apps, so replace %USERPROFILE% with the directory you want.
I have a directory which looks like this:
\isa\documents\2004\2008\jac\file1.txt
\isa\documents\2004\jan\file1.txt
\isa\scannedDocs\2004\2009\jan\file2.pdf
\isa\documents\2005\2008\jac\file1.txt
\isa\documents\2003\jan\file1.txt
\isa\scannedDocs\2002\2009\jan\file2.pdf
I have a list of files I need copied (exported from a database), but because I don't need EVERY file in the directory, I only want the ones copied from my list:
Files-needed.txt:
\isa\documents\2004\2008\jac\file1.txt
\isa\documents\2004\jan\file1.txt
\isa\documents\2004\jac\file3.txt
\isa\documents\2003\jan\file1.txt
Basically:
I'll need to copy out the specific files needed, and
Log when a file can't be found, and,
I need folder structure retained, as the files might have the same name, just in different directories.
It's on a windows 7 machine, and I can run PowerShell and batch files. I tried robocopy and xcopy and either got all of the directories and no files or all files and no directories...
Any assistance would be great.
EDITS:
Okay, so i have tried Robocopy, but it is either copying the directories and no files or files and no directories. I haven't tried anything in powershell yet, but that might be the way...
It is Windows, I might have just written the slashes incorrectly above, I work between both environments, and was just trying to explain the problem.
Things I tried:
#echo off
set src_folder="C:\batchScripting\TEST_DIR\"
set dst_folder="C:\batchScripting\COPY2_DIR\"
robocopy "C:\batchScripting\TEST_DIR" "C:\batchScripting\COPY2_DIR" FileList.txt /S /V /NP /LOG:"log.log" /R:10 /W:30
and
#echo off
set src_folder=C:\batchScripting\TEST_DIR\
set dst_folder=C:\batchScripting\COPY2_DIR\
for /f "tokens=*" %%i in (File-list.txt) DO xcopy /s /i "%src_folder%\%%i" "%dst_folder%"
#ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir"
SET "destdir=U:\destdir"
FOR /f "delims=" %%a IN (q23221996.txt) DO (
IF EXIST "%sourcedir%%%a" (ECHO f|xcopy /y "%sourcedir%%%a" "%destdir%%%a" 2>NUL >nul
) ELSE (ECHO "%sourcedir%%%a" does NOT exist)
)
GOTO :EOF
I used a file named q23221996.txt containing your data for my testing. sourcedir and destdir are both set up to suit my system.
The /y on the xcopy command forces overwrite if the destination file already exists.
I have a Windows Directory with about 8000 subdirectories. In each subdirectory there is a single zip file.
Is there a way I can batch script the move of each zip file to be moved to the parent directory, and then delete the subdirectory it was in? (Sub folder)
I know I can use xcopy to move files, but I'm not sure how to loop through the entire directory of sub directories.
Thank you!
#ECHO OFF &SETLOCAL
FOR /f "delims=" %%a IN ('dir /b /a-d /s *.zip') DO (
MOVE "%%~fa" ..
RD "%%~dpa"
)
I have folders that have the following structure:
/folder/processed_2013_0101
/folder/processed_2013_0223
etc.
What I'm wanting to do, is write a batchscript to move all of the files out of the most recent processed folder.
How would I go about specifying which folder that is?
#ECHO OFF
SETLOCAL
FOR /f %%i IN ('dir /b /ad \folder\processed_*') DO SET mrf=%%i
ECHO Most recent=%mrf%
Then move %mrf%\* destination
wherever destination is...