I'm trying to convert a bunch of wpd filed into docx with libreoffice, so far I have been able to achieve it but the resultant docx files are saved in just one folder (Ale) instead of Ale and its subdirectories, and what I want is for the docx files to be saved in the folder the wpd file are in. So far I have:
set path=%path%;"C:\Program Files (x86)\LibreOffice 5\program"
for /r %%f in (*.wpd) do (
soffice.exe -headless -convert-to docx:"MS Word 2007 XML" -outdir "S:\Temp\Ale" %%f)
Like #aschipfl said, go to the directory of each file and then do the conversion:
setlocal enableDelayedExpansion
set "path=%path%;C:\Program Files (x86)\LibreOffice 5\program"
for /r %%f in (*.wpd) do (
pushd %%~dpf
soffice.exe -headless -convert-to docx:"MS Word 2007 XML" "%%f"
popd
)
endlocal
Related
How add a text like test in FirstOfFile Name with Batchfile
I have some PDF file in a directory. How i can add text "Test" to First Of File Name
My file is like
1.pdf
2.pdf
3.pdf
I want have when Run
test1.pdf
test2.pdf
test3.pdf
How about the following samples? When you use these samples, at first, please set set add=test
Pattern 1
If there are only PDF files in the directory with PDF files, you can use following batch file. But when you use this, please put this batch file to outside of the PDF directory. When there is this file in the same directory to PDF directory, this batch file is also renamed.
#echo off
set add=test
for %%a in (*) do ren %%a %add%%%a
Pattern 2
If there are PDF files and other files in the directory with PDF files, you can use following batch file. In this case, the batch file and other files are not renamed. Only PDF files are renamed.
#echo off
setlocal ENABLEDELAYEDEXPANSION
set add=test
set i=0
for %%a in (*.pdf) do (
set ar[!i!]=%%a
set /a i=!i!+1
)
set /a i=!i!-1
for /l %%e in (0,1,!i!) do (
ren !ar[%%e]! %add%!ar[%%e]!
)
If I misunderstand your question, I'm sorry.
I have the following batch file code which when run in a folder, checks the file extension, creates the folder against the file extension and finally moves the file into folder name with extension name i.e. it will create .gif folder to move all gifs into it and .jpg folder to move all jpg's into it and so on.
I have no expertise in writing a batch file but all I need is to change this code in such a way that all file may go into the folders in such a way that all image file should go in "Images" folder, all video files in "Videos", all documents files (pdf,docs,xls etc.) in Docs folder, all Audio files should be in Audio folder and so on......
Can anybody help???
#echo off
rem For each file in your folder
for %%a in (".\*") do (
rem check if the file has an extension and if it is not our script
if "%%~xa" NEQ "" if "%%~dpxa" NEQ "%~dpx0" (
rem check if extension folder exists, if not it is created
if not exist "%%~xa" mkdir "%%~xa"
rem Move the file to directory
move "%%a" "%%~dpa%%~xa\"
))
#compo The file types with respect to categories are as follows: -
Docs
.docs,docx,xls,pdf
Video
.avi,.mpeg,.mp4
Audio
.mp3,.wma
Image
.jpg,.bmp,.gif
and so on......
The category name should actually the folder name.
Since your listing is small you could probably just add the information to your script file instead of a separate file:
#For /F "Tokens=1*Delims=:" %%A In ('FindStr/B : %0'
) Do #RoboCopy/MOV . "%%A"%%B>Nul
#Exit/B
:Docs: *.doc *.docx *.xls *.pdf
:Video: *.avi *.mpeg *.mp4
:Audio: *.mp3 *.wma
:Image: *.jpg *.bmp *.gif
Edit the last four lines as necessary, it should be self-explanatory to do so.
Edit
Using a separate file, FileCats.txt:
Docs: *.doc *.docx *.xls *.pdf
Video: *.avi *.mpeg *.mp4
Audio: *.mp3 *.wma
Image: *.jpg *.bmp *.gif
...and the batch file, Categorise.cmd:
#For /F "UseBackQTokens=1*Delims=:" %%A In ("FileCats.txt"
) Do #RoboCopy/MOV . "%%A"%%B>Nul
Make sure there's a space after the :
#echo off
for %%s in (Images Videos Docs Audio) do md .\%%s 2>nul
rem For each file in your folder
for %%a in (".\*") do (
set "moved="
rem check if the file has an extension and if it is not our script
if "%%~xa" NEQ "" if "%%~dpxa" NEQ "%~dpx0" (
for %%s in (pdf doc xls) do if /i "%%~xa"==".%%s" set "moved=Y"&move "%%a" ".\Docs\"
for %%s in (mpg avi) do if /i "%%~xa"==".%%s" set "moved=Y"&move "%%a" ".\Videos\"
IF NOT DEFINED moved (
rem check if extension folder exists, if not it is created
if not exist "%%~xa" mkdir "%%~xa"
rem Move the file to directory
move "%%a" "%%~dpa%%~xa\"
)
)
)
Note : MD ... 2>nul suppresses the error message when the directory can't be created (because it already exists)
First, create the directories to hold the collections.
For each file, first set moved to nothing (ie. "clear" it so it's undefined)
Then check the extension in a case-insensitive manner (/i) against a list of extensions to be placed in the collection. If you find a match, set moved to some value (like Y) and move to the appropriate collection. After all collection lists have ben examined, if moved is still`nothing (ie not defined) then move the file to the directory as determined by the extension.
(untested)
I am trying to change the file extension of all .rtf-files to .doc in a folder and all subfolders.
I found a great solution here: Rename files in sub directories
But my file fails when it encounters long file-names (The syntax of the command is incorrect.)
for /r %%X in (*.rtf) do (
ren %%X *.doc
)
I am up for totally different solutions as well. Working in a large file-environment that has been changed to Office 365 that does not support rtf - but does support them when renamed to doc.
Enclose in quotes:
for /r %%X in (*.rtf) do (
ren "%%X" "*.doc"
)
I currently have a windows folder with only two files in it:
vacation.jpg
and
summer.avi
What I want to to is rename summer.avi in vacation.avi by using the text that is before the .jpg extension.
So for example if I have another folder with christmas.jpg and summer.avi the .avi file would be renamed into christmas.avi.
Any help would be much appreciated!
You can use the ~n parameter extension to grab just the filename without the extension. The script needs to be in the same directory as the jpg and avi, but if you want to run it on multiple directories, you can wrap the whole thing in a second for loop.
#echo off
setlocal enabledelayedexpansion
:: This assumes there is only one avi file in the folder
for /F %%A in ('dir /b *.jpg') do (
set basename=%%~nA
ren *.avi !basename!.avi
)
This should worlk, though I haven't tested it:
#echo off
for %%i in (*.jpg) do set src=%%i
ren *.avi %src%
Hi I am looking for a (simple) batch script for Windows XP to copy pdf files with different filenames but having the same reference numbers in their filenames to a specific folder in a different drive.
E.g.
Copy all pdf's with reference number 111 to folder "test"
Source files in F drive
F:\folder 1\filename 1_111.pdf
F:\folder 1\folder 2\filename 2_111.pdf
Destination folder in C drive
C:\test\
I am a novice, so thank you in advance for your help.
Regards,
Olive
This is another option:
#echo off
for /f "delims=" %%a in ('xcopy /l /e /y "F:\folder 1\*111*.pdf" "c:\test\" ^|find ":"') do copy "%%a" "c:\test"