Pachilles

Member
  • Content count

    9
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Pachilles

Profile Information

  • OS
    Windows 7 x64
  1. OMG OMG! Life saver! I'm sooo pleased! So, this should work for all types of files (last code suggestion: changing *.txt to *.*)? SETLOCAL EnableDelayedExpansion for %%i in (*.*) do ( set MyFile=%%i set Myfile=!MyFile:.removethis=! rename "%%i" "!MyFile!" ) Oh, and having .removethis, actually being .remove.this won't mess with it (having an additional period)? Testing... testing... excited testing... This would solve ALL of my renaming issues! Tested and works! YES! I bow to the master! <later> Ok, calm now. 35k+ files with the unwanted text... easy fix, never the problem. Managing the constant flow of new files with the offending text? Big Pain. But no longer... thanks to you.
  2. A simple renaming of files becomes a serious headache, and I'm not sure why it's getting so complicated. Folder: C:\My Files Example list of files: Mr. Apple.removethis.txt My.apples.are.rotten.removethis.txt ThisAppleIsBad.removethis.doc I Like Apple Pie because apples are great.(Awesome even).removethis.pdf ... Obviously (by my examples), I want to remove .removethis from all of the file names. Simple, right? RENAME (like most DOS) gets confused with spaces in files and folders. RENAME gets lost with the use of periods. I can usually work around these issues, but for some reason everything I try causes different things to happen to different files, and every work-around I come up with falls flat somewhere. I won't even try listing them, except my latest attempt. BTW... I've manipulated where my quotes are... pretty much everywhere, and this is my best result. I just know that I'm missing something really simple... but this whole mission was supposed to be simple. BAT: for %%i in (*.txt) do ( set MyFile=%%i rename "%MyFile%" "%MyFile:~0, -11%.txt" ) Results in:
  3. I really like that concept, and in other situations that would be perfect (already thinking of some possibilities). The problem with THIS one is that this is part of the cleanup and organizing before allowing a database to run an automated scrub of everything internal to each file. I've already had to scratch everything and start over. Getting this external automation working takes a huge load off my manual workload... especially when considering the continuous flow of more files being added. BTW, I've run this in a sub-group of the actual files, and I've found a few additional scenarios. Add these files to see: Pineapples - The first cut.txt The Big Apple (New York).txt Since Pineapple includes "apple", it's moved incorrectly. Putting a space in front of the word check fixes it... but messes with everything else. The Big Apple... causes issues if the word checked isn't at the beginning. Here's the fixed code that allows these as well (also added remarks to beautify): @ECHO OFF REM ****************** Loop subroutine for each item in List.txt FOR /F "delims=;" %%i in (List.txt) do ( call :testsub "%%i" ) GOTO :End REM ****************** Subroutine(s) REM ****************** Search the filenames for an instance of the list item anywhere (with a space in front of it) :testsub FOR /F "delims=;" %%j in ('DIR /B *" "%1*.*') do ( IF NOT EXIST .\%1 md %1 MOVE "%%j" .\%1\ ) REM ****************** Check the beginning of the filename for the list item FOR /F "delims=;" %%j in ('DIR /B %1*.*') do ( IF NOT EXIST .\%1 md %1 MOVE "%%j" .\%1\ ) GOTO :EOF :End Also of note... List.txt needs to be arranged in a way that puts the more important folders to be hit first. For instance, if I include "grape" in the list as a catch all for any grapes not accounted for (red grape, seedless, etc), it should be put under the more specific grape types. This is, of course, not an issue if the files are not moved or deleted as in my code above. Thanks for the help everyone. I think I'll end up using this version. Maybe at another time, I'll create a script to search the folders and copy any multi-'fruit' files needed... then append it to this script.
  4. Thanks for reminding me that I can 1. subroutine within one bat file, and 2. multi-line within (). Much prettier! :-) I did get a set of quotes in that managed to give me a "White Grape" folder instead of just White, but the "white grape" file didn't copy. I'll give your cleaner version a try. I think the location of quotes may be better. The del next to the copy matches my original "move" command, that I tried, but I pulled it out because the "...and orange..." file never made it to the Orange folder. I haven't found a better place to delete, though. I'm thinking that either I make it not delete any file with "and" in it, until after the script is finished, or I do a scan/commit process. If I scan and sort into a text file that decides where all the files are going, and then run again for the actual copy/del... Any ideas? EDIT: Your quote location made moving files with spaces in them to move, and my original location allowed for 2-word folders. Having both worked beautifully! @ECHO OFF FOR /F "delims=;" %%i in (List.txt) do ( call :testsub "%%i" ) GOTO :End :testsub FOR /F "delims=;" %%j in ('DIR /B *%1*.*') do ( if not exist .\%1 md %1 copy "%%j" .\%1\ ) GOTO :EOF :End Now once I find a good location for the DEL, I'm all set... If I can't... I might have to rethink the handling of those multi-fruit files.
  5. It would indeed need to mark it but , copying wouldn't be a good solution as it would slow with big files and take too much space. To resolve this, i would use depending on the filesystem shortcut creation or hardlink. Also as i understood first, you needed to create folder automatically so the name of the files you need to process might perhaps be parsed to create the list of folder and decide which file will go where and if it will need to go in many folders. But from the filenames provided, it may not be possible unless you decide that it is the first word of the name of the file and word separator can be either space or dot (but then which word would need to be parsed to get the second like in the case of apple.and.orange.comparison.001.txt). Also fruits with space in their name wouldn't be parsed properly. The folder names being listed in the txt file is the search criteria searching the file names for all words in a given folder name should do it. Getting IFs, ANDs, ORs, proper quote usage, and deleting is the real trick here. Holding off the deletion of a file with "and" in it, until completion... maybe. Possibly a scan/commit process.
  6. I'll definitely check into the above solutions/suggestions, but I'm getting pretty close with the following: List.txt Apple Orange Pear White Grape Purple Grape Kiwi Test.bat FOR /F "delims=;" %%i in (List.txt) do (call Test-Sub.bat %%i) && (del *%%i*.*) Test-Sub.bat FOR /F "delims=;" %%j in ('DIR /B *%1*.*') do (if not exist .\%1 (md %1)) & (copy %%j .\%1\) Test files: apple pectin recipe #1.txt apple.and.orange.comparison.001.txt Apple.Cores.Type3.#02.txt white grape juice 05 (10-5-2012) (Compressed).txt The above results in: In the CMD window: C:\>FOR /F "delims=;" %i in (List.txt) do (call Test-Sub.bat %i ) && (del *%i*.* ) C:\>(call Test-Sub.bat Apple ) && (del *Apple*.* ) C:\>FOR /F "delims=;" %j in ('DIR /B *Apple*.*') do (if not exist .\Apple (md Apple ) ) & (copy % j .\Apple\ ) C:\>(if not exist .\Apple (md Apple ) ) & (copy apple pectin recipe #1.txt .\Apple\ ) The syntax of the command is incorrect. C:\>(if not exist .\Apple (md Apple ) ) & (copy apple.and.orange.comparison.001.txt .\Apple\ ) 1 file(s) copied. C:\>(if not exist .\Apple (md Apple ) ) & (copy Apple.Cores.Type3.#02.txt .\Apple\ ) 1 file(s) copied. C:\>(call Test-Sub.bat Orange ) && (del *Orange*.* ) C:\>FOR /F "delims=;" %j in ('DIR /B *Orange*.*') do (if not exist .\Orange (md Orange ) ) & (cop y %j .\Orange\ ) File Not Found C:\>(call Test-Sub.bat Pear ) && (del *Pear*.* ) C:\>FOR /F "delims=;" %j in ('DIR /B *Pear*.*') do (if not exist .\Pear (md Pear ) ) & (copy %j . \Pear\ ) File Not Found C:\>(call Test-Sub.bat White Grape ) && (del *White Grape*.* ) C:\>FOR /F "delims=;" %j in ('DIR /B *White*.*') do (if not exist .\White (md White ) ) & (copy % j .\White\ ) C:\>(if not exist .\White (md White ) ) & (copy white grape juice 05 (10-5-2012) (Compressed).txt .\White\ ) The syntax of the command is incorrect. C:\>(call Test-Sub.bat Purple Grape ) && (del *Purple Grape*.* ) C:\>FOR /F "delims=;" %j in ('DIR /B *Purple*.*') do (if not exist .\Purple (md Purple ) ) & (cop y %j .\Purple\ ) File Not Found C:\>(call Test-Sub.bat Kiwi ) && (del *Kiwi*.* ) C:\>FOR /F "delims=;" %j in ('DIR /B *Kiwi*.*') do (if not exist .\Kiwi (md Kiwi ) ) & (copy %j . \Kiwi\ ) File Not Found Resulting organized as: C:\Apple C:\Apple\apple.and.orange.comparison.001.txt C:\Apple\Apple.Cores.Type3.#02.txt C:\White C:\white grape juice 05 (10-5-2012) (Compressed).txt I've apparently forgotten a bit of my batch skills, and having syntax issues. I played with quotes to fix my issues, but everything just got worse. Also, I don't feel safe with using the del command where it's at (even after fixing the rest), but copy without an automated delete will overflow my HDD once I'm using the actual files (they total around 350 GB). Some where along the way, I lost the getting an Orange folder
  7. I've used a FOR loop to process line by line before, but it was many years ago and don't remember how I did it. I've been avoiding VBS, but I'll check it out. Throwing some test files into a test folder and running this gave me a text file named "apple" (no extension), with "APPLE: -" in it. I'm imagining a FOR loop to create an array storing each line of my text file, then using MD %%variable after DIR finds something, then moving it. I'm not sure how I'd code that.
  8. I have a .txt file listing all possible names (about 400) to create folders with. Simplified Example: apple orange pear white grape purple grape kiwi I have a large number of files (about 30,000) with similar (but not very clean) names, that I need to organize into folders and also to cleanly rename. Simplified Example: apple pectin recipe #1.zip Apple.Cores.Type3.#02.zip apple.and.orange.comparison.001.doc white grape juice 05 (10-5-2012) (Compressed).rar They should be renamed and put into the correct folder(s): Results Example: C:\Apple\Apple Pectin Recipe #001.zip C:\Apple\Apple Cores Type3 #002.zip C:\Apple\Apple And Orange Comparison #001.doc C:\Orange\Apple And Orange Comparison #001.doc C:\White Grape\White Grape Juice #005 (10-5-2012).rar I don't want the folders created until a file is found for it (an empty Kiwi folder would just be annoying). Getting the files put into the folders is my primary problem, renaming is secondary since I have a 3rd party app that can help reduce my manual renaming time if necessary. Two BATch files for this is highly preferable, since I can incorporate them into my other automation easier. Does anyone have any suggestions?