Copy files in different subdirectories to another directory using a file list - powershell

so I have a list of about 26,000 files that I need Copied/moved to a different directory on a server. The different files in the list all have different sub-directory locations and names in the main source folder and the paths are specified in the filelist document.
The source filepath is on a network drive so (V:\RandomFolder\RandomSubdirectory)
The destination filepath would be on the local machine so (C:\RandomDestination)
I looked into seeing of robocopy could pull from the file list and move that way but I couldn't seem to find a way to make that work. Anyone got any ideas? I'd really appreciate any help.

Okay I figured it out, if anyone runs into this conundrum just follow like what is below( and edit to your liking and save it as a .bat
`#ECHO ON
SET FileList=C:\listoffilestomove.txt
SET Source=\\TopLevelOfNetworkOrFolderSourceDirectory\
SET Destination=C:\yourdestination
FOR /F "USEBACKQ TOKENS=*" %%F IN ("%FileList%") DO XCOPY /F /Y "%Source%\%%~F" "%Destination%\"
GOTO :EOF`

Related

Simple xcopy script using variables and a target text list to copy a folder to different computers

I wrote a script that wil copy a particular folder to a list of hosts, stored in a text file.
It works great from a short source path but fails to find the folder when located in a long path, which is how i need it to function.
Thsi what i tried, which should copy the folder to the list in the text.
Code below
set source=%~dp0%data
set source2=%~dp0%\target.txt
FOR /F "TOKENS=*" %%A IN (%source2%) DO XCOPY /d /y /f /i "%source%" "\%%~A\c$\users\test\test"
pause
Error: The system cannot find the file C:\Users\lenovo\OneDrive\Company\Red.
The above path is not the full path.
I understand there may well be more modern ways to achive this such as ropcopy or powershell and am open to ideas if this is not teh best method.
Thanks in advance for any help

Windows script to merge all .html files in a directory and its subdirectories into a single .html file?

I have a Results directory, which has many subdirectories each containing a HTML file with a specific naming format, _ExeReport.html.
I want to write a Windows script which merges each of those files into one file.
For now, I tried running two commands :
dir /S *_ExeReport.html
This is listing all the files (with some extra information), and:
copy /b *.html final.html
This is merging all the files in current directory into one file.
But, I am not able to write a script which can combine and do everything I need.
Can someone help me with this? I am newbie to scripting languages.
Thanks to #T3RR0R for sharing the link. My final command :
FOR /F "tokens=*" %G IN ('dir /b /s *_ExeReport.html') DO TYPE "%G" >> MergedOutput.html

Move files from multiple folders to a single folder without extension

i am a windows user and i need help with something
i have a folder and in it it has multiple folder.and in those multiple folders i have more folders and in those folder i have files without any extension like jpg,txt etc
here is a sample
D:\test\1\something1\1235486[file]
D:\test\1\something2\1235486[file]
D:\test\2\something1\1235486[file]
D:\test\2\something2\1235486[file]
so now i want to move all those random number files i.e 123456789[these files are without any extension] to D:\newtest
so i will have files like
D:\newtest\123456789
D:\newtest\123456789
D:\newtest\123456789
D:\newtest\123456789
etc. i could have easily done this with search option if it had a extension.but what can i do now?
Finally Found a solution for this problem
First make another folder where you want to transfer file
lets say i have a folder named ABC and i want to transfer its files to XYZ [only files not folders]
then open Command prompt [cmd]
and enter this
for /f "tokens=*" %a in ('dir /b /s /a-d "d:\abc"') do #copy "%a" "d:\xyz
Change the folder names and hit enter.it will transfer all the files in it

How to use Robocopy to copy a template folder structure to other folders?

I need to copy all the folders within one folder, to multiple other folders. The folder structure I want to copy from is here:
x:\Customer1\Site1\
I want to copy all the folders within Site1, to all the folders within the following directory:
X:\Customer1\
Obviously I don't want to copy the folders back into Site1 again, only every folder within Customer1, excluding Site1.
Site1 contains 19 folders. I would like to end up having those 19 folders within every folder in the Customer1 folder. Can someone please tell me how to achieve this?
I have been looking at the Robocopy MS page to learn about all the switches and options, but there doesn't seem to be anything to help me with this 'copying folder tree from one folder to multiple folders' that I need. Please give me any reference
Many thanks
Naz
As far as I know, this is only possible with xcopy's /t-switch which copies only the folder structure (note that if you also want empty folders to get copied you have to put the '/e' -switch as well)
To copy the structure in every subfolder a for-loop is the way to go:
set customer1="X:\Customer1"
set site1="Site1"
for /f %%d in ('dir %customer1% /b /ad') do (
if %%d NEQ %site1% xcopy %customer1%\%site1%\*.* %customer1%\%%d\*.* /t /e
)

MSDOS command(s) to copy files matching pattern in directory structure to local directory

I have a job that periodically runs and archives files into a folder structure that looks like this:
ArchiveFolder
TimestampFolder
JobnameFolder
job<timestamp>.xml
For a given job, I'd like to collect all xml files in the archive folder into a flat directory (no subdirectories, just all the files) without having to drill down into each one, examine for the proper job, then copy the file.
It seems there should be a fairly straigtforward way of doing this. Any suggestions?
EDIT: I guess I wasn't clear here. The TimeStampFolder will have a name of something like 2011-07-24, the JobnameFolder will have a name like FooFeed or BarFeed, and the job file will have a name like job2011-07-24.xml. There are hundreds to thousands of TimeStampFolders, and each one may have one or more job folders in it. Given a specific job name, I want to collect all the files in all the directories that match that job type, and dump them into the local folder, with no subdirectories.
EDIT1:
SET JOB=JobName
SET OF=OutputFolder
START /wait NET USE Z: "\\ServerName\Sharename\ArchiveFolder" password password_here /USER:domainname\username /P:NO
PUSHD Z:\
FOR /F "USEBACKQ tokens=*" %%A IN (`DIR /b /a:d /s ^| FIND /I "%JOB%"`) DO (
FOR /R %%F IN (%%A) DO (
COPY /Y "%%~fF" "%OF%"
)
)
POPD
It basically locates each subdirectory of ArchiveFolder that includes the JobName in it, then digs into each one that it finds to copy the files out of them.
EDIT2:
Added NET USE to access your network share to perform tasks on the files. If your local machine already has the UNC assigned to a driveletter, you can remove the NET USE command line and change Z: to the assigned driveletter.
#ECHO OFF
FOR /R %%v IN (job*.xml) DO COPY "%%v" c:\out\