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")
Related
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.
I'm trying to figure out how to match folders with a dot in the file name (e.g., ".svn") in a Windows batch script.
Here's the basic script:
setlocal
pushd c:\myDir
#echo off
FOR /D /r %%G in ("*\.whatever") DO (
echo %%G
REM do stuff
)
#echo on
popd
endlocal
This works just fine for most folder names (e.g., "*bin"), but I can't figure out the method to specify a folder with the dot. "*.whatever" and "*\.whatever" return no results. I'm guessing I'm missing some escape character or something equally simple, but I haven't been able to find any documentation on it.
(Before anyone asks, no I'm not trying to recursively delete subversion folders; "*.svn" is just an example.)
Maybe I am missing something, but as you say it seems simple
for /r /d %%a in (.*) do echo %%~fa
But if the folders are hidden, the normal for will not be able to see them, so we need to execute a dir command an process its output with a for /f
for /f "delims=" %%a in ('dir /ad /s /b .*') do echo %%~fa
I'm using Windows and I have a huge list of files
something nextthing.ext
other something.ext
banana apple.ext
I'm trying to generate the following:
something nextthing.rar
other something.rar
banana apple.rar
I've done some research and I couldn't find how to do this. I know WinRAR has a built in way to do this, but it won't let me keep the names. It just renames them to Foldername1.rar, Foldername2.rar ....
I tried using the following command line:
for /f "delims=|" %f in ('dir /b "C:\Users\Adam\
Desktop\Files"') do rar a %f *.rar
However, it doesn't generate all files and they seem to be named wrongly...
For example, what should be banana apple.rar becomes banana.rar and apple.rar
Okay, found how....
#echo off &setlocal
set "path=C:\Program Files\WinRAR;%path%"
:indiv
echo(
echo(
FOR %%i IN (*) do (
rar a "%%~ni.rar" "%%~i" || echo Error building archive!
)
You can use in a command prompt window to compress each file in a directory into a separate archive:
for /f "delims=" %f in ('dir "%USERPROFILE%\Desktop\Files" /B /A-D') do "%ProgramFiles%\WinRAR\Rar.exe" a -ep1 -idcdp "%~nf.rar" "%f"
Important are the double quotes around %f as some file names contain 1 or more spaces and in this case the file names must be enclosed in double quotes.
Above command for usage in a batch file:
#echo off
for /f "delims=" %%f in ('dir "%USERPROFILE%\Desktop\Files" /B /A-D') do "%ProgramFiles%\WinRAR\Rar.exe" a -ep1 -idcdp "%%~nf.rar" "%%f"
This command ignores subfolders because of /A-D. It compresses only each file in directory Files on desktop of current user.
Following Windows batch command converts all tif images in the folder C:\RootFolder\Folder1.
for %%i in (C:\RootFolder\Folder1\*.tif) do "Tiff2Pdf.exe" -o C:\RootFolder\Folder1\%%~ni.pdf %%i
How can I do it for all the folders available in RootFolder?
RootFolder
-Folder1
-Folder2
-Folder3
.
.
Thanks for your time
There's another way - just to add it:
#echo off
for /r "c:\rootfolder\folder1" %%a in (*.tif) do "Tiff2Pdf.exe" -o "%%~dpna.pdf" "%%a"
I also changed the loop variable to a because i is close to l and I and 1 in many fonts.
FOR /F "delims=" %%i IN ('dir /b /s C:\RootFolder\Folder1\*.tif') DO "Tiff2Pdf.exe" -o "%%~dpi%%~ni.pdf" "%%i"
Use dir /s /b to do a full recursive enumeration
Use FOR /F "delims=" to parse the results and handle paths with spaces.
Use the %%~dpi%% to get the directory of each file.
Use %%~ni to get the file's name with out an extension.
This question might have a simple solution, but I just cannot find it.
Let's say I'm using the DIR command to produce a list of .txt files in the folder "E:\Documents". How can I make sure that only the .txt files one level below "E:\Documents" are listed (i.e. in a direct subfolder) and not the files in "E:\Documents" itself. "E:\Documents\\" or "E:\Documents\*\" doesn't seem to do the trick.
Thanks in advance!
FOR /f "delims=" %%i IN ('dir /b/ad') DO IF EXIST ".\%%i\*.txt" DIR ".\%%i\*.txt"
That's if you want the output in DIR format - with headers
FOR /f "delims=" %%i IN ('dir /b /ad') DO IF EXIST ".\%%i\*.txt" (
FOR /f "delims=" %%q IN ('DIR /b ".\%%i\*.txt" ') DO ECHO ".\%%i\%%q"
)
if you want just the filenames.
This can be achieved without dir:
for /d %%d in ("C:\basedir\*") do for %%f in ("%%~fd\*.txt") do echo %%~ff
If you need not only the file names, but also detail information about the files, add the respective qualifiers, e.g.:
for /d %%d in ("C:\basedir\*") do for %%f in ("%%~fd\*.txt") do echo %%~azff
a → attributes of the file
t → timestamp of the file
z → size of the file
See help for for details.