Set docx. properties using .bat - batch-file

I need to create the same word documents basically every day to create reports. I would very much like to automate this using batch-script (or any script will do, really, as long as it also creates folders).
I have a .bat that creates the set of folders I need that looks like so:
#echo off
set /p dname= Enter Directory Name?
md %dname%
md %dname%
md %dname%\docx
md %dname%\xls
md %dname%\ppt
Now I need to copypaste a file to the docx folder that I have in the root folder, called intial.docx. This file needs to be renamed into
Initial_[Incrementing number]_V1_[Title].docx.
And I also need to set file properties of those files, namely Subject and Comments.
How do I do all that?

Well for the copy paste and renaming section, you could use the copy and rename commands:
#echo off
copy "directory\path\filename.docx" "directory\newpath\filename.docx"
rename "directory\newpath\filename.docx">"directory\newpath\newfilename.docx"
pause
That should work, let me know if you have any problems :)
For the properties, I guess you could just enter those into a text document,that's what I do.

Related

Create folder structure and copy file inside without specific path

I'm new to the site and tried to search for an answer a couple of days and found similar situations as mine, but not entirely the same and apologise in advance if there is an answer already somewhere.
I've created a batch script to make a small folder structure to organise my photos, and so far so good, it's working as expected here the code
#echo off
MD 1.Capture
MD 1.Capture\Selected
MD 1.Capture\Discard
MD 2.Projects
MD 3.Masters
MD 4.Web
MD 5.Instagram
Now the part I'm struggling with is copying the same file in each folder and subfolder.
The actual file will always be the same and is in a specific path that never changes, but I'd like to have the code to copy that file in the folders without specifying the folder's path, and instead make the folders and put the file inside no matter where the structure is, the reason why is that I will place the script in different places all the time and having to correct the path all the time will make the code useless to me. Is that possible?
And thanks in advance.
It wasn't absolutely clear to me which directories you wanted the source file, in this case C:\Users\Giovani\Pictures\Portrait.jpg, to be copied to, So I'm offering two complete batch-file options, where the final directories will be placed along side the batch file itself.
The first will copy to each 'new' directory, including 1.Capture:
#Echo Off
For %%G In (
"1.Capture"
"1.Capture\Selected"
"1.Capture\Discard"
"2.Projects"
"3.Masters"
"4.Web"
"5.Instagram"
) Do %SystemRoot%\System32\xcopy.exe "C:\Users\Giovani\Pictures\Portrait.jpg" "%~dp0%%~G\" /CHIKQRY 1>NUL
The second will do the same, creating the 1.Capture directory, but not copying to it:
#Echo Off
SetLocal EnableExtensions
For %%G In (
"1.Capture\Selected"
"1.Capture\Discard"
"2.Projects"
"3.Masters"
"4.Web"
"5.Instagram"
) Do %SystemRoot%\System32\xcopy.exe "C:\Users\Giovani\Pictures\Portrait.jpg" "%~dp0%%~G\" /CHIKQRY 1>NUL

Batch - Rename multiple files to sequential numbers

I need to rename multiple files at once. Lets say I have a these files:
episode1.mkv
e1.mkv
s01e01.mkv
As you see, the file names have nothing in common.
How can I change the names of all the files to numbers (1.mkv - 2.mkv - 3.mkv ...) using batch.
I want the first file to be renamed to 1.mkv (no letters or spaces or anything else in the name) the second file to be renamed to 2.mkv, and so on.
I've looked around the internet a lot and I still didn't find anything that does exactly this.
TIA
Batch file version
#echo off
setlocal ENABLEDELAYEDEXPANSION
set/a fileNum = 1
for %%f in (*.mp4) do (
ren %%~nf%%~xf !fileNum!%%~xf
set/a fileNum += 1
)
GUI version
FreeCommander can do this for you.
Run FreeComander
Navigate to the folder.
Select all the files you want to rename.
Hit F2
The rename dialogue will appear. To rename all files names to be numeric do this:
Click Rename to make the change.
I suppose you could make a FOR /L loop with a limit of the amount of files in your directory, feed it a DIR /B |FINDSTR .mkv line by line renaming each file to an index variable you keep. Since you are going to name them into just numbers your DIR command will spit the same movie back as the first item over and over so maybe write the output of DIR /B|FINDSTR .mkv to a text file and work off of that? Or move the file you rename to another folder?
Once you make a rough project we could help you refine it? Or use FreeCommander and make a batch to do the rest you want to do after that.

.bat coding or some app maybe?

how can I organize my directories automatically?, I have a "downloads" folder, which currently contains lots of different info, for example, work related info, tv-shows, movies, etc, software, etc.
How can I automatically, maybe using some .bat execution, not sure, check for example the name of the files, or the type, and put them in the right subfolders?.
Thanks!.
You can use the move command to move files. You can also use wildcards in it.
So you could write a batch script that looks something like this:
cd C:\Users\You\Downloads
rem Excel sheets are work.
move *.xls Work
rem Reports are work.
move Report*.pdf Work\Reports
rem Pron and other viewing material ;)
move *.mp4 Private
You could run this script automatically by making it a scheduled job. Note that this script changes to the right directory first and then moves items to a relative subdirectory. This means that the directories Work, Work\Reports and Private must exist in the Downloads directory.
Of course you can expand the script to make it check and create directories as well, or you can specify different paths if you want to move the files out of the Downloads directory.
Basically, try to do it on the command line and then try to generalize those steps into your script.
This batch file will create a set of folders like .mkv .jpg .mp3 using the filetypes inside the folder, and move the files into the appropriate folders.
Launch it from your desktop and change the "c:\media" to the right folder name.
#echo off
cd /d "c:\media" && for %%a in (*) do md "%%~xa" 2>nul & move "%%a" "%%~xa" >nul

Recursively move all files to one-upper directory

So here are the questions:
I have a folder, let's say C:\myFolder, and in this directory, I have many subfolders, and in each of this subfolders, I have exactly one folder, that contains pdf files, so my file structure looks something like this: C:\myFolder\someFolderInMyFolder\theOnlyFolderInThisFolder\*.pdf, now I want to move all these pdfs one level up, such that it will be like this: C:\myFolder\someFolderInMyFolder\*.pdf. Are there any command line commands, or scripts (that can be executed by Cygwin) that will help me with this?
What could complicate the situation is that, I have manually move some files one level up by myself, so it will help if there is a check condition.
I have some .zip files that the name are generated by computers, in the format of mm/dd/yy/fileIndex.zip, and the fileIndex is like No.001, for example. When I upload the extracted folders to Dropbox, and view the files on my iPad, it looks weird because the full folder name can not be displayed completely, so I want to rename each folder to someIndex, in the above example, from No.001 to 001, so same question here: any command or shell scripts?
You can move all PDFs up one level with a slightly modified version of what #Endoro suggested:
#echo off
for /r "C:\myFolder" %%f in (*.pdf) do move "%%~ff" "%%~dpi.."
However, there is no generic way for the script to distinguish files you already moved from files that have yet to be moved. It might be best if you undid your manual moves. Otherwise you'll have to find some distinguishing feature or check each name against a list of names, e.g. like this.
You can rename files like this:
#echo off
setlocal EnableDelayedExpansion
for /r "C:\myFolder" %%f in (No.*.zip) do (
set name=%%~nxf
set name=!name:No.=!
ren "%%~ff" "!name!"
)
endlocal
FTR, I somehow doubt that you really have files with names like mm/dd/yy/fileIndex.zip. Forward slashes are not valid characters for file names in Windows.

Renaming file paths in batch files

I need to execute several rename commands in a batch file and wish to store the batch file in a directory different from the directory storing the files that need to be renamed.
The following is a sample file
ren C:\test\old1.txt new1.txt
ren C:\test\old2.txt new2.txt
I would ideally like to not have to copy the directory path everytime, since I might need to change the folder in which these files reside. I tried the following but it does not work. Probably I am not understanding the set command correctly.
set dirpath=C:\test\
ren %dirpath%old1.txt new1.txt
ren %dirpath%old2.txt new2.txt
Any ideas how I might achieve this effect.
Your batch file seems to be correct. Just to make it play well with path names that contain embedded spaces, put double quotes around the name, like so:
set dirpath=C:\test\
ren "%dirpath%old.txt" new.txt
Obviously, if you have a hardcoded path (C:\test\) you shouldn't even need that. I tried your batch file locally and worked fine.

Resources