Move or Copy Files within subfolders to another folder - scripting

I've been searching around for quite some time but nothing I've found seems to work for me.
I would really like to move the files to another folder on the same drive if possible just in-case the drive happens to be low on space. but none of the move scripts i found seemed to work for me.
i've tried using move, move-items, copy, xcopy, and even robocopy.
robocopy is the only one to work for me so far even tho its creating a new file, it also creates a subfolder that the file is in. in the new location.
so this how my work looks so far
D:\DVDBD-Projects\Project1\
Movie1\
Movie2\
Movie3\
there is a .mkv file in each movie folder and I would like to move the .mkv in each folder under projects to a new location without creating the folder it was originally in.
So the .mkv files will be moved to D:\DVDBD-Projects\Complete without any folders just mkv files.
This is my code
robocopy "D:\DVDBD-Projects\Project1" "D:\DVDBD-Projects\Complete" *.mkv /s
this will copy the files to the new location but also create the movie1 folder and so on. if i dont use the /s switch it wont look inside the subfolders and copy the files.
So i was hoping you guys could help me out, is there a way that i can copy or move just the .mkv files to the complete folder.
i plan on adding this code to script that encodes the movies from my camera so it saves me alot of point and clicking and cutting and pasting.
*note - looks like i can use this code
pushd "D:\DVDBD-Projects\Project1"
for /r %%a in (*.mkv) do (
MOVE "%%a" "D:\DVDBD-Projects\Complete\%%~nxa"
)
popd
this will take all files from subfolders and move them to the destination folder
i could probably also install xxcopy which extends xcopy which would allow me to copy the files from sub directories without creating new folders in the destination

for /f "delims=|" %%s in ('dir /ad/b') do robocopy "\\source\%%s\" "destination\" *.mkv /s

Related

Robocopy Creating Hidden Folders On Backup Drive

I am using Windows 11 Pro (since late November '21), before that Win 10 Pro.
For many years I have been happily backing up my files [ROBOCOPY] to a hidden NAS share but recently I retired the NAS and moved to a USB solution (USB Docking Station, 2TB Drive), removing drives in between backups. Which is where things started to go a bit weird because some of the folders didn't appear on the backup drive. Using TreeSizeFree I can see that the folders and their sub-folders/files are there (all entirely visible, of course) have copied across, I just can't see the folders in question.
Here is a sample line from my script:
robocopy C:\Games E:\Games /v /e /xo /w:5 /r:2 /log+:E:\bak-Games.log /tee /copy:dat /dcopy:t
robocopy S:\ E:\Shared /v /e /xo /w:5 /r:2 /log+:E:\bak-Shared.log /tee /copy:dat /dcopy:d >
The top line works as expected but the bottom one doesn't.
I've checked all the switches I'm using and none of them appear to do anything that might account for this behaviour.
I've tried a number of solutions including using the "/a-:sh" switch, making sure that files aren't hidden and pre-creating the folder in question but it just makes them invisible.
The only thing that appears to be a common factor between lines of the script that work and those that don't is that the ones that do are copied from folders (into appropriately named folders on the backup drive) while the ones that don't are copied from partitions i.e. (in the sample script lines above):
robocopy c:\games to e:\games. [WORKS AOK]
robocopy s:\ to e:\shared. [WORKS, ROOT FOLDER NOT VISIBLE]
Any advice appreciated :)
Thanks
James

OneDrive Multiple Folders/HardDrives Sync

I have 3 hard drives. I would like to sync specific folders from each drive with MS OneDrive.
One hard-drive cannot hold all the files from all hard drives.
How can I do this with OneDrive?
What I have done in the past is use symlinks to sync everything to OneDrive, and maintain the folder structure I want. For example, when coding, I like to keep my source folders on the root of C:, so that I can easily access it from menus (C:\coding). So what I'll do is create a folder in OneDrive called coding then symlink it to the root of C: using cmd.exe
mklink /d "C:\Link\Location" "C:\Users\USERNAME\OneDrive\Path\To\Source\Folder"
mklink /d "C:\coding" "C:\Users\USERNAME\OneDrive\coding"
Elevated permissions are required to do this.
You can do this with as many folders as necessary. Just remember, the source folder HAS to be in OneDrive. If you have existing folders that you want to sync, move them all to OneDrive and then symlink them to where they originally were located. Example:
mklink /d "C:\Users\USERNAME\Documents" "C:\Users\USERNAME\OneDrive\Documents"
mklink /d "C:\Users\USERNAME\Desktop" "C:\Users\USERNAME\OneDrive\Desktop"
mklink /d "C:\Users\USERNAME\Favorites" "C:\Users\USERNAME\OneDrive\Favorites"
mklink /d "C:\Users\USERNAME\Desktop\Vacation Pics" "C:\Users\USERNAME\OneDrive\Vacation Pics"
mklink /d "C:\Whatever I want" "C:\Users\USERNAME\OneDrive\Whatever I want"
--edit--
There is also the application Link Shell Extension that I have found extremely useful. Full instructions are found at the link, but... It integrates with Windows' Explorer shell and adds an item to the context menu. You can right click a folder to select it as the symlink source, then left click in the directory you want the symlink to be located. I think it does other things as well, but this is all I use it for. FYI, it requires VCRedist 2005 if memory serves, and does not include that dependency bundled.
For now, MS OneDrive client application only supports one folder. You would need to move all your files into that one folder.
You also cannot use Windows Explorer Libraries as the OneDrive folder - since those are NOT really folders.
Directory links are also not supported in some versions of windows. (http://www.howtogeek.com/174765/how-to-sync-any-folder-with-skydrive-on-windows-8.1/)
The Solution
What I used in the end is SyncDriver - does everything you need from any folder:
http://syncdriver.com/
First you set up the one folder where all the online stuff will go. Then you add any folder - from any drive - and it all goes to OneDrive. Simple and easy to use.
You also have options to only sync in specific directions:
OneDrive => local
local => OneDrive
Bi-Directional

Move folder structure from one computer to another computer when these computers aren't networked?

I have two computers that aren't networked. I need to replicate the folder structure of one drive that exists on one computer and put it on the other computer. Both Windows 7 machines. I don't need the files, just folders/directories. The drive letters are the same on both computers (Y). The computers are miles apart physically, but I do have access to the computer I am trying to get the folder structure of via LogMeIn.
I am thinking I need to save the folder structure to a file using some process. Move that file to my computer (via email or LogMeIn File Manager) and run some process to put in on my computer.
Is there a better solution? If not, is there code out there to do this via VBA, Cmd window, .bat script, VB.NET, or VBS? I know I can write it in VBA, but I'd rather not recreate the wheel if I don't have to.
I don't have a 'process'/program that does this. LogMeIn File Manager doesn't do this either (I asked). There are lots of paths on this drive that I need so creating them by hand would take a long time. I searched and found a lot of solutions that work with computers that are networked, but these computers are not networked, hence why I think I need to save it to a file. Again, I don't want all the files on the drive (its huge and most of the files are unnecessary), just folders.
thanks.
Create a directory listing of the source computer and redirect the output to a text file:
dir /ad /b /s >> dirlist.txt
The switches to dir are (more info at MS TechNet):
/ad List only files with attribute of directory
/b Bare format (no heading information or summary)
/s Displays files in specified directory and all subdirectories
Transfer dirlist.txt from the source computer to the destination computer.
On the destination computer, use a for /F with that text file from the command prompt to create the directory structure:
for /F "delims=" %i in (dirlist.txt) do md "%i"
The switches to for are documented at MS TechNet
You have many options:
Windows command xcopy source destination /T /E. The /T option creates the directory structure, and the /E option includes empty directories.
Bundle the empty directory structure into an installer (perhaps as a zip file).
If the structure isn't relatively small and not likely to change, you could just put a bunch of md commands into a batch file.
Combination - xcopy the structure locally, zip it, transfer it, unzip it.

Delete temporary files on startup

I have a program which when it runs it fills Temp folder with lots of .tmp files. This is causing C drive to fill up. I have been asked to investigate if it's possible to write a script in dos to delete temporary files on startup. I also wish to delay the program starting until all files are deleted. This would need to happen every time on start-up. It would be great if this could be installed via a flash drive.
I would be grateful on any pointers on how this could be done
The little batch I am using to delete my temporary files:
#echo off
rd %temp% /s /q
md %temp%
cls
echo Temporary Files have been deleted!
echo.
pause
%temp% is a path which always results in your current temporary folder. However note that there are more temporary file locations like C:\Windows\temp.
If you just want to delete TMP files, go with del C:\<MyPath>\*.tmp.
There are probably more sophisticated ways, but the good old fashioned del c:\Temp\*.* should be a good start.
There's a list of all the options, here: http://www.computerhope.com/delhlp.htm
You will probably want /F (delete read only), /S (sub-directories) and /Q (quiet)
I assume, the following row in c:\autoexec.bat file may help:
del c:\path\to\temp\files\*.tmp
Cheers for replies. This is what I'm using
c:
cd \
cd "c:\Documents and Settings\user\Local Settings\Temp\"
del *.tmp /f/s/q
echo All tmp files deleted.
pause
This seems to do what I want it to do. Now I need it to do this everytime PC starts up. Is there a way to install this via flash drive? ie write a batch file with all commands, put on flash drive. double click .bat file, now installed and will run on startup? (Have a number of PCs which need same thing)

script to move all files from one location to another location

can someone help me with a dos script to move all files from one location to another location
move <sourcepath>\*.* <destpath>
IE, if you wanted to move all files from c:\test\ to c:\test2
move c:\test\*.* c:\test2
if you want to suppress the prompt to overwrite files
move /Y c:\test\*.* c:\test2
If you want to move from the current directory, you can specify just the *.*. Also you can do relative paths. So if you want to move the current directory's files up one directory, you'd do
move *.* ..
.. being the shortcut for "up one directory"
If it's across the network, you can use a UNC path to authenticate as the user you're logged in as or map a drive (using the NET USE command) to specify a username/password on the remote computer, then copy using that drive letter. You can then delete the drive letter after you're done. UNC paths look like \\computer\share\folder\file.txt
I think this one
C:\> MOVE /Y *.* C:\Destination
should be corrected.
Use Robocopy. In Windows 7 and Windows Server 2008 R2 you can even run it multi-threaded using the /MT[:n] switch. From my daily "sync-before-shutdown" script:
Robocopy "d:\dev" "\\dolores\backups\carrie\dev" /e /MT /njh /njs /nc /np /nfl /ndl
(all the /n.. switches suppress console output which helps to speed up the copying process).
To move the files, use either /MOV or /MOVE (to move all subfolders) instead of /E.