batch file which looks for specific files - batch-file

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.

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

moving files one after one from one folder to another folder using batch script

I have 50 files in a folder and I want to move those 50 files one by one (not together) to another folder. For example after successfully moving the first file to a folder the second file will be moved. Similarly all 50 files should be moved one after one. I want to perform this task in a windows batch script. Any help would be appreciated. Thank you.
Regards,
Pinaki
use for and iterate over every file in the source folder.
for %%f in (*) do (
move "%%f" "destination\"
)
If you want to scilence the prompting use /Y

.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.

Need help with 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"

Resources