How to write a script to copy from a windows share (\\....\...) to a certain location in docker - powershell

How to write a script to copy from a windows share (\.......) to a certain location in docker.
I have tried the following to find the latest sub-folder in windows share.
FOR /F "delims=" %%i IN ('dir "\\....\.." /b /ad-h /t:c /o-d') DO (
SET a=%%i
GOTO :found
)
echo No subfolder found
goto :eof
:found
echo Most recent sub folder: %a%
Could Someone help me out with the script, as I am still learning?
TIA

Related

Rename only a specific part of every filename in a folder

I want to, for example, replace all -v1 parts in every filename for -v2. It's almost working, but the access is denied because the files are being used by the cmd process itself during execution. My current code is:
for /f "delims=" %%a in ('dir /a-d /b *-v1*') do ren "%%a" "%%a:-v1=-v2"
Any suggestions? :)
EDIT:
I've also tried for /r %%i in ("*-v1*") do ren "%%~nxi" "%%~nxi:-v1=-v2" and it finds the files and uses the correct rename value, but still outputs that it can't access the file because it is in use by another process. I'm sure that process is the cmd.exe itself, because after I close the command prompt, I can change the filenames manually without any problems.
I also tried by writing the current filenames to a temporary .txt file with the idea that the files I want to rename aren't used by any command. Then read the file with the type command within a for loop to rename each file, but same thing.
It's quite frustrating, any help is appreciated :)
substring substituion doesn't work with for variables (%%a). Use a "normal" variable and delayed expansion:
#echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /a-d /b *-v1*') do (
set filename=%%a
ren "%%a" "!filename:-v1=-v2!"
)

DOS: Copy one file (oldest) at a time

There is a folder which contains many zip files. I want to copy only oldest zip file on each commmand execution. Please help? Thanks
From How do I write a Windows batch script to copy the newest file from a directory? - but reversing the file order
FOR /F "delims=" %%I IN ('DIR . /B /O:D') DO COPY %%I NewDirectoryPath & EXIT

Batch file : copy all file except those its name contain some substring

first of all im beginner. i want to create batch file to search through specific folder (including all it subfolder) and copy all file inside it except those which filename contain some specific string,this is what i have so far
set now=fish
set logDirectory="C:\Users\paiseha\Desktop\bb\"
for /r %logDirectory% %%i IN (*%now%*.*) do (
rem copy process goes here
)
let say i have 3 file in it
C:\Users\fareast\Desktop\bb\one.txt
C:\Users\fareast\Desktop\bb\twofishtwo.txt
C:\Users\fareast\Desktop\bb\three.txt
so i want to copy file one.txt and three.txt only, but instead it copy only the second one,i know its because of *%now%*.* so how can i invert it so that it does the other way around, help me pls, thanks in advance
try:
#ECHO OFF &setlocal
set "now=fish"
set "logDirectory=C:\Users\paiseha\Desktop\bb"
for /f "delims=" %%a in ('dir /a-d/b/s "%logDirectory%"^|findstr /riv "^.*[\\][^\\]*%now%[^\\]*$"') do (
rem copy process goes here
)
EDIT: The \ character is represented as [\\] instead of \\ because of a quirk on how Vista FINDSTR regex escapes \. Vista requires \\\\, but XP and Win 7 use \\. The only representation that works on all platforms is [\\]. See What are the undocumented features and limitations of the Windows FINDSTR command? for more info.
for /f "delims=" %%a in ('dir /a-d/s/b "%logDirectory%" ') do echo %%~nxa|findstr /i /L "%now%" >nul&if errorlevel 1 ECHO COPY "%%a"
should work for you.

How do I create a batch file that will move ONLY subdirectories, and NOT the master directory

How do I move all of the sub-folders within a master folder, but NOT the master folder itself.
The source path is c:\book\music\
I don't want to move the master folder itself because I'm getting an I/O Device error.
What code can I use to do this? Kindly, please spell code out because I am a baby with the command-line :)
Here is a longish script, but it should work pretty well.
It uses "dir", but you might look at "forfiles" as well.
Forfiles is more flexible, but really it is difficult to use.
#echo off
#rem USAGE: MoveDirs From To
setlocal
set from="%~1"
set to="%~2"
if "%1"=="" goto :Usage
if "%2"=="" goto :Usage
for /f "delims=;" %%a in ('dir "%1" /ad /b ') do call :MoveIt "%1" "%2" "%%a"
goto :EOF
:MoveIt
move "%~1\%~3" "%~2" > nul || echo Failed to move %3 to %2 & goto :EOF
echo Moved %3 to %2
goto :EOF
:Usage
echo Usage: moveDirs.bat FromDirectory ToDirectory
goto :EOF
You might also want to read on XCOPY.
you can copy files, those only that are not empty subdirectories.
check the command to learn more about it.
xcopy /?

Moving all files from MANY folders up one level - command line

I have tens of thousands of *.wav files spread out across hundreds of folders. I need help to get command line to move all files up one level. The directory structure for all these files are identical, but the names of the folders vary slightly:
Z:\Audio\Level*\story*\VOCAB\*.wav
All files are located in the VOCAB folders, and I need to move them to the story* folders:
Z:\Audio\Level*\story*\*.wav
I can do this from command line by running a move command on each individual folder, but is there a way to run it recursively on all files within the entire directory? Can I use a wildcard in the location path?
Notes:
The * in Level* and story* are numbers 01-24.
I'm on Windows XP Professional.
Thanks for any help you can provide!
try something like:
for /r %F in (*.wav) do move %F %~pF\..
refer to for /? from command prompt as reference (particularly in case I didn't 'code' that quite right...)
I suggest starting it from within \Audio directory.
Found a similar question in another forum (http://www.computerhope.com/forum/index.php/topic,98046.0/all.html).
Modifying some of their code, here's a batch file script that might do the trick (please try on a small subset before unleashing it on everything):
#echo off
set thisdir=%cd%
for /f "delims=" %%A in ('dir /b /ad') do (
cd /d "%%~dpnA"
for /f "delims=" %%B in ('dir /b /ad') do (
echo Level 2 Directory: %%~dpnB
cd /d "%%~dpnB"
for /f "delims=" %%C in ('dir /b /ad') do (
echo Level 3 Directory: %%~dpnC
cd /d "%%~dpnC"
move *.* ..\
cd ..
rd "%%~dpnC"
)
cd ..
)
cd..
)
cd /d "%thisdir%