Need help understanding a move script written for CMD involving multiple subdirectories into one directory - cmd

I got a folder with a lot of images in it, and I'd like to move everything to the main folder so basically I would like to turn this:
L:\Pixiv\Tags\44324\Image1.jpg
L:\Pixiv\Tags\4564356\Image2.jpg
L:\Pixiv\Tags\325423\Image3.jpg
L:\Pixiv\Tags\16324\Image4.jpg
...into this
L:\Pixiv\Tags\Image1.jpg
L:\Pixiv\Tags\Image2.jpg
L:\Pixiv\Tags\Image3.jpg
L:\Pixiv\Tags\Image4.jpg
I did some looking, and I discovered a move function for CMD, and while most of it I can understand, some of it I can't, and frankly, I'm just that smart enough to know what happens when you start playing around with stuff you don't fully understand, so I don't do it. Point is your basic move function is basically something like "move c:\Whatever C:\Whocares," but as you can tell from below, this is a little more complicated.
for /r %d in (*) do move "%d" "d:\all snaps\"
/r I think goes through all the folders at the current target directory. So if I'm in L:\Pixiv\Artists and I type in this code for L:\Pixiv\Artists as a destination folder every file in Artists is going to be dumped into Tags. Is this correct?
%d I couldn't make sense out of, so I've no idea what it does. Also, for ease of use, I would like to put this in a batch script, because boy howdy, do I got a lot of folders that needs to be fixed. From what little I was able to read I should write the same as above, but change %d to %dd, correct? Also where at would I add a target directory, so I could just write a batch script, and be done with it? Also, apologies in advance for my lack of knowledge, usually I use Batchrun when it comes to automating stuff.

Related

How to individually compress all files in a folder with a batch file with 7zip?

I've seen questions that I think are similar (but which I cannot make work for me), but I am very new to batch files so I don't understand what needs to be different to make it work. I have a folder /source/ with some files, say:
red.txt
orange.txt
yellow.txt
green.txt
blue.txt
purple.txt
I need to make a batch file that will run 7zip on all of them automatically to create zipped version of them. I found some resources which I thought would help but after a few hours of frustration, I think I'm forced to confront the fact that I simply don't know enough about Batch files to understand why it isn't working?
My effort was:
:: Changes directory to this file's directory
cd %~dp0
:: Location of source data
set dirSource="C:\Source\"
:: Target location of zipped data
set dirTarget="C:\Target\"
cd %dirSource%
for %f in (%dirSource%*.txt) do
(
7z.exe a "%dirTarget%\%%~NF.zip" "%dirSource%\%%~NXF"
:: based on related searches on the internet
:: but I can't find an explanation of _why_ this is supposed to work, which makes it hard to know why it isn't
:: ie, what does "a" do? What is ~NF vs ~NXF? etc
)
Lastly - I have been utterly unable to find a good comprehensive guide to batch files because of all the weird character modifiers. Since I don't expect to pick it all up in this question, if anyone has a good guide where I can look up what some of these seemingly random character combinations mean I would be forever grateful.

Possible to copy/move/etc multiple files of same base name via Windows CMD/.BAT?

I am wondering if it is possible to accomplish the following, given some context and example.
I have files in "Server\Share\Folder\File##.ext"
Sometimes the "File##.ext" can be "File01.ext" through "File20.ext", and other times it may be "File01.ext" through "File40.ext"
Sometimes there are less of these files, sometimes there are more.
I want a batch file to take the files from "Server\Share\Folder\File##.ext" and move them to "Server\Share\OtherFolder\File##.ext". I know I can accomplish this easily with:
copy /y "Server\Share\Folder\File01.ext" "Server\Share\OtherFolder\File01.ext"
Then just add another line for each extra "File02.ext, File03.ext, etc., but I am wondering if it is possible to make it so that any file that resembles "File##.ext" can be included, so that no matter how many ## I have, it always works without issue.
Thanks in advance for any and all advice!
EDIT
Someone mentioned using Wildcards, but my question with that is - lets say those files are File01.ext through File05.ext, will it match what it finds to the newly moved file? Like will it find File01 from File?? on the source and Make it File01 from File?? at the destination?
You can accomplish this task with a FORloop program in batch-file.
You can also loop through the Commands using : and variable name.
Combining these two would help you get what you want.
We can help you with Ideas and little bit of the coding. But the Efforts must be done by you. So U can learn programming better

renaming mass files from o to xxxx

I would like to rename multiple folders of files from
Blackmagic Cinema Camera_1_2013-12-06_2248_C0001_000000.dng
…
Blackmagic Cinema Camera_1_2013-12-06_2248_C0001_000322.dng
to
0.dng
…
322.dng
So in fact from 0 to xxxx (for safety get to 5 digits if necessary)
I am really new to the terminal tool (on mac osx 10.8) and cannot do the dumbest thing with it, I just know it's the most reliable way to do it, and as they are quite precious files for a project I'm not that keen on using a regular rename application that may do I don't know what slightly more than just rename those files, I just want them to be as pure as they are with the names changed.
So I read many stuff on here but as I know absolutely nothing about any command I can't interpret what was listed on the numerous topics on how to rename as they don't exactly apply to what I want to do. So if you could guys explain to me things as dumb as I am for it to be simple and comprehensible (what has to be explained, actually I just want something to work, not a class), would be great. This forum seems to have good answers quickly, seems all nice
Ah, btw, I would actually run that for a single file first (as a try) and after use it for all the folders of these like-named files. So it's like
Blackmagic Cinema Camera_1_2013-12-06_2321_C0005
…
Blackmagic Cinema Camera_1_2013-12-06_2327_C0000
for the folders names, each one containing a pile of files named like stated in the first part of this message. so i guess it would need something to apply to all folders of a chosen folder, as there are numerous ones.
(ah, when I say i'm the dumbest guy about it : I can understand, but just have no clue on this stuff, so if you could even tell me how to get to that file/folder/directory etc. whatever be needed to complete it for someone knowing 0)
Thanks in advance, very much !
From the directory containing your DNG files:
awk -F"[_.]" '$(NF) ~ /dng/ {system("mv "$0" "($(NF-1)+0)".dng");}' <(find .)
It worked for me in linux, and it should work in mac os too.
If you have any problem, just leave me a comment ;-)

Creating a Continuous File Reading-Executing Shell Script

I need to write something that will read and execute all the files(Mainly executable scripts) inside one or more folders; in other words, a continuous chain with a break when finished. I'm new to shell and need syntax help. I'm on Ubuntu 12.10-Gnome btw.
Here are some main highlights I think should be included;
-The program should ask for one or more directories. Should process all the files given in these directories,
-Should create a .txt file on which files and folders are read and executed(for correction and informational purposes),
-Could contain a break option like control+shift+c maybe but thats clearly not of utmost importance.
The code, or the guidance to the code would be very much appreciated. Thx alot.

Getting safe temp folder in Windows

I need to get a safe temp folder where I could store temporary files for my application, but so far my research has lead me to conclusion that all approaches I've found are flawed.
The first idea was to use GetTempPath function, but that causes two problems:
The folder might not exist, so I would have to truncate folders one by one up to root, and recreate them if they do not exist back to full path (error prone, tedious)
From "Larry Osterman's WebLog" click it seems that GetTempPath might fallback to USERPROFILE or Windows directory and extract whole lot of files right in there, which is SUPER BAD(TM)!
In the same post, there is a suggestion to use GetEnvironmentVariable, but this seems a dangerous function to me (missing TMP & TEMP envvars for instance).
Is there a cleaner function I could use? Seems that SHGetKnownFolderPath has no clue what temp folder is.
Your program is probably not the only one to rely on GetTempPath, so it's reasonable to expect it to return a proper writable path. Especially since Windows automatically initializes the TMP and TEMP environment variables for you; someone would have to go to some trouble to override them, and it would be their responsibility to make sure the change did not mess up their system.
I would go ahead and assume GetTempPath works properly, and worry about failures when you try to create the temporary file - there are other errors that might occur at that time that you need to check for anyway.
An idea would be to get the path where your application is (GetModuleFileNameEx combined with GetModuleHandle(NULL) and GetCurrentProcess) since this directory cannot be deleted under windows as long as your application is running from it (maybe I'm wrong ...some years ago I couldn't do this :) ) and in this directory create a temporary directory.
Your first bullet point is the solution. Wrap it up in a method so that you don't duplicate code.
According to this answer, Boost's Filesystem library can be used for this.

Resources