This isnt really a coding question. I need to put all my files into individual directories so each file has its own directory with the name based on the filename.
So before i go make an application to do this, does anyone know any software that can do this? like Automator or something.
No need to build an application. This simple one liner run from the Windows command line will move each file in a directory into a sub-directory based on the root name of the file.
for %f in (*) do #(md "%~nf"&move "%f" "%~nf")>nul 2>&1
Two files with the same base name but different extensions will be moved into the same directory. For example, "test.txt" and "text.doc" will both be moved into a directory named "test"
Any file without an extension will not be moved.
If you want to run this from a batch file, then
#echo off
for %%f in (*) do (
md "%%~nf"
move "%%f" "%%~nf"
) >nul 2>&1
You requirements were not very clear. If your requirements differ, then the script can probably be modified fairly easily to suit your needs.
Related
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
I need help creating a batch file to find multiple files named the same thing in 100's of files and replace the with a different file...
Alternatively, is there a program that will do this if I select the 2 different files that will search and replace them...
Find file from computer Pairing = High School DxD - Kuroka.png
Replace file with Pairing = High School DxD - Kuroka (F).jpg
Since you never provided the basic information such as What directory you wish to start a search from or You wish to convert or just rename, I will assume you wish to search your photo's folder (Including sub-directories) and simply rename file.jpg to file.png.
To search photo's and all its directories we can use the FOR /R to search for all .jpg files and DO to address the action. The script bellow will do the following.
Search and replace all .jpg extensions to .png in the photo folder directory
Batch Script:
#ECHO ON
#CD C:\Users\%username%\Pictures
For /r %%A In (*.jpg *.jpeg) Do ren "%%A" "*.png"
goto :eof
I have a batch file (ReduceFLACPadding.bat) to reduce padding in all FLAC files within a directory using metaflac.exe
These FLAC files are stored in subdirectories (one per album) within the directory E:\FLAC Library
At the moment I am processing my FLAC files one album at a time, moving the batch file to the targeted subdirectory each time. (The batch file is set to process all FLAC files within a directory)
My question is; is there a way to run this batch file on all the *.FLAC files in all the subdirectories of E:\FLAC in one go?
Please let me know if you need any more information
Windows 7
I would change the command that finds the *.flac files to find it recursively rather than running the batch file itself on every directory.
for /r "e:\flac" %%a in (*.flac) do echo metaflac "%%~fa" "%%~da" "%%~pa" "%%~na" "%%~xa" "%%~nxa"
should provide at least a clue. Without an example metaflac command, a more precise response would take excessive research.
From the prompt, try for /? for details. I've just shown with an echo how to construct some possible source/destination components - the rest is a matter of judicious adhesion of strings. Note the use of quotes however to properly cater for spaces in file/directorynames
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
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.