Create Seperate Directory Names From a List of Files and Then Move Into Them - Page 1
Forum section: electronics / general

author: bostonman
author_rank: Super Contributor
timestamp: October 29, 2024, 03:23:05 am
content: Not sure if my subject line makes sense.I collect manuals in PDF format for vintage C64 video games. Normally I get them in ZIP format, and, when I extract them (either single or a bunch of ZIP files), I let WinZip unzip them into separate directories which they are created based on the ZIP file name.i.e. file.zip gets unzipped into a newly created directory named file with the ZIP contents in it.I take this approach because I began getting more files related to that particular game, so I realized having separate directories made more sense for future needs.Earlier I got a single ZIP file with almost 1000 PDFs in it and would like to keep the same structure.Does a way exist that will create a directory based on the file name (leaving out the extension) and then move that file into the newly created directory; I'd need this done in a batch since I have almost 1000 PDFs?The next issue I'll have should a way exist to do this will be eliminating the duplicates and/or how to handle having that directory already, however, this is another story.

author: DimitriP
author_rank: Super Contributor
timestamp: October 29, 2024, 05:12:07 am
content: Creates a folder for each filename without the extension and then moves the file onto it.For those that are into that sort of thingCode:@echo offsetlocal enabledelayedexpansionrem Check if a parameter is providedif "%~1"=="" (echo No filename pattern specified ie: *.pdfexit /b)rem Loop through each file matching the wildcard passed as a parameterfor %%f in (%1) do (rem Get the file name without the extension and the file extensionset "filename=%%~nf"set "extension=%%~xf"rem Create a folder with the file name if it doesn't existif not exist "!filename!" (mkdir "!filename!")rem Set the destination pathset "destpath=!filename!\%%~nxf"rem Check if the file already exists in the folderif exist "!destpath!" (set "suffix=a"rem Loop to find the next available suffix:find_suffixset "newdest=!filename!\%%~nf-!suffix!%%~xf"if exist "!newdest!" (set /a "suffix=!suffix! + 1"for %%i in (!suffix!) do (set "suffix=!suffix:a=z!")goto :find_suffix)rem Move the file with the suffixmove "%%f" "!newdest!") else (rem Move the file without suffix if it doesn't existmove "%%f" "!destpath!"))endlocal

author: abeyer
author_rank: Frequent Contributor
timestamp: October 29, 2024, 09:30:27 pm
content: Probably not what you're looking for given the windows references... but for anyone else with a similar problem for whom it is a fit, don't forget aboutvidir(which, despite the name, respects whatever your$EDITORis.)It makes big rename/move/delete tasks like this into a quick text edit.

author: bostonman
author_rank: Super Contributor
timestamp: October 30, 2024, 12:45:33 am
content: QuoteDid you create that or did you already have it?Also, which language is that in? I don't know much about programming, so uncertain where to go with the code.

author: DimitriP
author_rank: Super Contributor
timestamp: October 30, 2024, 01:02:31 am
content: Paste it it into notepad and save it as movem.bat in the same folder as your 1000s of pdfsOpen a command prompt window CD to the same folder and while in the folder run: movem *.pdf

author: bostonman
author_rank: Super Contributor
timestamp: October 30, 2024, 02:34:58 am
content: That worked perfectly, thanks!I know a bit about .bat files, however, not to the extent you created.