windows


Batch file to move bottom folder into specified location


I have a directory structure which contains files organized into folders by an associated ID
..\abc\STORAGE\123
..\abc\STORAGE\234
..\xyz\STORAGE\345
..\xyz\STORAGE\456
I want all of the bottom subfolders, and all their contents, to be copied into a new directory such that afterwards I will have:
..\SomeNewDir\123
..\SomeNewDir\234
..\SomeNewDir\345
..\SomeNewDir\456
How should I accomplish this, using a batch script?
Test this: launch it in the folder that holds the abc and xyz folders.
#echo off
for /d %%a in (*) do xcopy "%%a\storage\*.*" "c:\somenewdir\" /s/h/e/k/f/c
#echo off
setlocal enableextensions
set "sourceRoot=%cd%"
set "target=d:\test"
for /r /d %%a in (*) do (
set "bottom=1"
for /d %%b in ("%%~fa\*") do set "bottom="
if defined bottom (
echo move "%%~fa" "%target%"
)
)
This will search the last directory in each sub branch of indicated source, independtly of name, and move (when the output to console is correct, remove the echo) the subdirectory to the target folder

Related Links

Batch file to run other batch files with parameters
Find opened process in Windows batch
How to edit BATCH start command to start a file in folder above
CreateProcess hook to add CommandLine
how to refresh a Matlab window and leaving it where it was in the Z-order
How to capture Perl output on Windows (Strawberry perl)
Windows App Certification Kit error
Php Script to delete and create files and folder using .bat not working when run using Windows Scheduler
I am trying to make .jks file process automatic
Existing Directory Not Found by Batch Script
Express/connect 'connect.sid' session cookie not created windows 10
Batch file net user command
Escaping forward slashes : Windows CMD and Bash
Tab completion and arrow keys don't work in GHCI in Git Bash
.htaccess on filesystem not working
Windows 10 task scheduler errors “task not supported”

Categories

HOME
go
google-app-engine
object
swt
hessian
obfuscation
knitr
owl-carousel
javacc
yandex
big-o
emscripten
babeljs
code-coverage
jax-ws
special-characters
joomla3.0
teechart
jquery-ui-sortable
octave
endeca
mod-security
xcodebuild
filechannel
magnetic-cards
google-picker
blade
babel
r-mice
react-toolbox
ios10.2
google-cloud-print
slidetoggle
delimiter
soot
failover
aws-codecommit
r-grid
clickjacking
dsx-desktop
github3.py
instantiation
activexobject
carriage-return
modalviewcontroller
least-squares
roblox
sim-toolkit
unordered-map
dcmtk
openal
clarifai
hammer.js
context-switch
boxing
skin
boo
seek
segment-io
google-cloud-console
myspace
adafruit
project-organization
finalbuilder
eoferror
uvc
mmwormhole
qtwebengine
sonarqube-5.0
punycode
linkedin-jsapi
angular-carousel
ray
draw2d-js
android-audiorecord
openargs
solace-mq
mongohq
tlf
mvc-editor-templates
onmousemove
xcode3.2
zope.interface
saleslogix
wcf-configuration
inkcanvas
jquery-address
winmain
cac
tabpanel
nstokenfield
alsb
wysiwym

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile