Need help with batch-file - batch-file

I have a very poor experience in writing batch-files.
And I need to do the following:
directory contents 2 files - .exe and .zip
I need to write batch file, merging these two files with resulting file named after zip-file.
In hardcoded variant it looks like this:
copy /b init.exe+archive.zip archive.exe
But it would be great if I could put in my directory zip-file with arbitrary name, click on my bat-file and get the exe-file with the name same as my archive's name.
P.S. (init.exe is never changes and directory will always containt only one zip-file at a time)
Thanks a lot for any help with this.

Something like this should do the job, I think:
FOR %%f IN (*.zip) DO COPY /B init.exe + "%%f" "%%~nf.exe"

Related

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.

Create Zip of all files in a subfolder with a batch script

I'm trying to create a batch script which is creating a .zip file including all files of a subfolder and which is named with the name of each subfolder.
If already tried to work with /f %%F but nothing seems to work. My currently working code looks like this:
for /d %%X in (*.*) do "C:\7zip\7za" a "%%X.zip" "%%X\"
which is giving me the correct named .zip file but without taking the files out of the subfolder so that my files look like this:
example.zip
-- example
---- example1.txt
---- example2.txt
I am thankful for any help. It feels like theres not too much to make it work like i need it!

batch file which looks for specific files

I'm wondering if a batch file could help to move all the files which i need from a couple of folders to a specific one. The folder structure looks like this example below:
d:\home\\(random)\upload\\*.*
d:\home\\(random)\uplaod\\*.*
The files in the directory upload should be moved to a specific folder. It can be done by putting every single path in to the batch file, (there are more then 100 folders and there will some more in the future). I guess there is an easier way to get this done.
Thanks for you help in advance.
for /d %%a in ("D:\home\*") do echo move "%%a\upload\*" "x:\destination\
This is the syntax for use in a batchfile. For use on commandline replace every %%a with %a.
The for /d returns subfolders of D:\home\. Just append the upload\* part.

I want to copy files, listed in a .txt file, into a new folder

I have roughly 2000 documents in one folder and I want to seperate them into different folders.
I have created a "documents.txt", which lists every file I´m interested in.
The .txt file reads as:
C:\Users\NIE\Desktop\test2\one.pdf
C:\Users\NIE\Desktop\test2\two.pdf
C:\Users\NIE\Desktop\test2\three.pdf
So now I went on creating a .bat file:
#echo off
FOR /F "delims=" %a IN (C:\Users\...\Desktop\test2\documents.txt) DO COPY "%%~a" "C:\Users\...\Desktop\test2\kopieren\%%~nxa"
The folder structure is like:
In "...\Desktop\test2", all documents are located. In a subfolder ("...\Desktop\test2\copy"), the specific documents (as listed in the documents.txt) should be copied.
While running my code, I´m getting the statement:
%C:\Users\...\Desktop\test2\one.pdf
The syntax for the filename, path is wrong
0 files were copied.
So I guess the "%" seems to be the bad guy here. I tried different styles for the .txt file, like
one.pdf
userprofile%\Desktop\test2\one.pdf (thought I could use the first % for completing the "%userprofile%" stuff
Every solution I could find via google did not worked either, the formatting of the .txt file seems to be a problem in my case.
Really looking forward for you answers :)
Looks like you have done a fatal mistake: %a
Fixed:
FOR /F "delims=" %%a IN (C:\Users\...\Desktop\test2\documents.txt) DO COPY "%%~a" "C:\Users\...\Desktop\test2\kopieren\%%~nxa"

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.

Resources