windows bat file copy issue - windows

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.

Related

Adding file extensions to files without them in Windows

I am trying to add file extensions to a large number of files located in a series of folders and subfolders in Windows. For some reason, these files do not have a file extension on them and I need them to have the extension .ddd so I can convert them to PDFs using a separate program.
cd R:\PRODUCTION\92
ren *. *.ddd
Note that this command does indeed work but only on folders that actually contain the files I need, and no subfolders. What could I add or change to hit all files in all subfolders? Thanks in advance.
Please try the following command. If it looks like it will do the correct rename, remove the ECHO from the REN command line.
CD /D R:\PRODUCTION\92
FOR /F "delims=" %f IN ('DIR /S /B /A:-D "*."') DO (ECHO REN "%~f" "%~nf.ddd")
In a .bat file script, double the percent character on the variable.
CD /D R:\PRODUCTION\92
FOR /F "delims=" %%f IN ('DIR /S /B /A:-D "*."') DO (ECHO REN "%%~f" "%%~nf.ddd")

Spaces in foldername causing fail in batch processing of sub-directories listed in text file

My ultimate goal is to individually zip subfolders of a main folder in one swoop from the top directory. So imagine this structure
Top-Folder
-Bob
--Folder-1
-Steve
--Folder-1
--Folder-2
-Tim
--Folder-1
From Top-Folder, I'd like to run a batch script that individually zips up each of the sub folders. So in the above example, I'd have four zip files, for each of those sub folders. They would reside alongside the original folders.
folder-1.zip (from Bob)
folder-1.zip (from Steve)
folder-2.zip (from Steve)
folder-1.zip (from Tim)
I have this so far:
if exist list.txt del list.txt
if exist subfolders.txt del subfolders.txt
REM create list of all users (top folders)
dir "F:\Top-Folder" /AD /B >list.txt
REM create list of all subfolders
for /F "delims=" %%i in (list.txt) do dir %%i /AD /S /B >> subfolders.txt
REM now you have all subfolders in subfolders.txt so you can zip them one by one
for /F "delims=" %%X in (subfolders.txt) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\"
With simple test folder names this is successful. However with my real folder names, whilst list.txt is generated with the top folder names, subfolders.txt is not created and ergo the zipping can't happen.
Examples of the real folder structure/names:
2005-05-11 - Tappehallerne, Copenhagen/[AUD #1] MD(M) - CDR(1)
2005-05-11 - Tappehallerne, Copenhagen/[PRO #1b] HDTV
What do I need to change to have the subfolder names written to the second text file for the rest of the script to execute?
for /F "delims=" %%i in (list.txt) do dir "%%i" /AD /S /B >> subfolders.txt
You need to "quote the name" otherwise dir looks for "quote" and "the" and "name"

Want to batch move all files from directories into the parent directory and delete the subdirectory

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"
)

how to traverse specified subfolders in a windows batch file?

Here is my folder hierarchy:
[Numbers]
[Numbers/12545]
[Numbers/12545/dev]
[Numbers/12545/prod]
[Numbers/32445]
[Numbers/32445/dev]
[Numbers/32445/prod]
...
[Numbers/.....]
[Numbers/...../dev]
[Numbers/...../prod]
I want to copy some text files under the only "[Numbers/...../dev]" folders. How should i do?
I tried the below code and it's not work because it coppies under the all subfolders.
for /r %NUMBER_DIRS% %%d in (.) do (
copy %PROJECT_INPUTS%\*.txt "%%d"
)
Thanks.
Try this:
for /d /r "%NUMBER_DIRS%" %%d in (*DEV) do copy "%PROJECT_INPUTS%\*.txt" "%%~d\*.txt"
#ECHO OFF
SETLOCAL
FOR /f "delims=" %%i IN (
'dir /s /b /a:d "\numbers" ^| findstr /i /e "\dev"'
) do ECHO COPY %PROJECT_INPUTS%\*.txt "%%i\"
This will report what the batch PROPOSES to do. Remove the ECHO keyword before the COPY to execute the copy.
Note : you may need to add /y to the copy options if you want to OVERWRITE an existing file in the destination directories.
I presume that you're copying FROM %PROJECT_INPUTS% TO many ...\dev directories.

Suppress directory names being listed with DIR

I want to list the files in a folder but not sub-folders. DIR enables you to list specific types of files (hidden, archive ready etc) and also only folders but I cannot see how to list only files.
I need the following statement to return files for further processing, but folder names are messing things up!
for /f %%a in ('dir /b %csvPath%') do (
)
dir /b /a-d will give you files without directories. Note there is no space between /a-d. The '-' says "NOT" directories.
From the dir /? help information:
/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files - Prefix meaning not
/B Uses bare format (no heading information or summary).
dir /b /s /a-d
/s lists every directory and all subdirectories containing files, and (a-d) without empty directories.
dir /b /s /a-d /p
/p pause
dir /b /s /a-d > list.txt
You could use:
dir /b /a-d
Which will suppress directories being listed.
The /A switch has a few other options to assist with filtering:
/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files I Not content indexed files
L Reparse Points - Prefix meaning not
Use dir /B /A-D to get files only.
You want the /A-D option:
for /f %%a in ('dir /A-D /b %csvPath%') do ( )

Resources