Move files to folder in same directory but for 2,000 separate directories - windows

I've searched all over and seen many similar questions but nothing I was able to tweak and make work for my situation.
I have files in a folder like this
C:\music\unknown-folder-name\*.*
And I want to move all of them to
C:\music\unknown-folder-name\disc1
This seems so simple but I can't figure it out. I'm happy to use PowerShell or regular command line or a batch file or whatever works. Thanks for your help.

Related

Windows 11 - Not kind sort command for viewing all files in subfolders

I used to use a sort command when trying to view all files across a bunch of folders at once. It makes sorting files easier. I do know part of the command was written as not sort kind, however I am unable to remember which parts need to be capitalised, and where the colon (:) goes. I have trying googling the answer, and even gone through hours of YouTube videos trying to find the answer. I would prefer not to use the asterisk (*) command or the DIR command Screenshot showing one of many attempted iterationsas that is not suitable for my use. Thank you.
I have since been alerted on StackExchange that the answer to the issue I was having is kind:NOT Folder.

How do I get batch to recognise a folder with a . in as a folder?

I have a batch file which needs to rename a folder from Profile.Win7 to Profile.Win7.%currentdate%.
Right now I'm just using the command
move /y %userprofileaddress%\Profile.Win7 %userprofileaddress%\%backupfolder%
which doesn't throw an error (as far as I can see) but just doesn't do anything.
The folder isn't in use, so any ideas?
Edit: It works now... I wasn't running as admin. facepalm
I think that it is easier to obtain answers if you directly describe the corresponding processing and results of the batch file in the question.
Both works well and not work examples. And if there are error messages etc.
According to the contents of the current question, it seems that it renames the folder itself rather than moving or copying the files in the folder.
In that case, if there is a program using the corresponding folder and files and folders in it, you should not be able to rename.
Please check whether such a situation has occurred.

Oneway sync of Windows folders

I have a folder where I don't want to modify any existing files in.
But I want to be able to add and remove files easily and recognize these files easily.
I thought in something like a SymLink but I want one folder where only the added files are shown and then the source folder with all files.
Is there anything like this? Or do you have a better idea?
Okay I found SyncToy from microsoft.
It has an echo mode which does what I wanted.

Powershell script to remove files that are not in use

I'm trying to write a script that removes all files from a given directory, however I don't want to remove files that are currently in use (being viewed, edited, etc.). What I'm finding is that for some file types (.docx, .xlsx, etc.), this works just fine and the .ps1 script fails as expected and moves on. However, some files (.bmp, .txt) can be open and get deleted as well. It looks like certain files are not locked when in-use. I guess my question is a few smaller questions:
Is there a way to tell if files are in-use (other than seeing if it's locked)?
Is there any definitive way to tell which file types are locked when in-use?
Is there a better cmdlet than Remove-Item to use for what I am trying to achieve?
Thanks in advance!
Some applications like Word locks the file wile reading them to avoid it being modified while it's open (usualy in case you want to modify it in ex. Word). Other applications, like notepad, doesn't.
This is not specific to a filetype (which is just a GUI attribute that has nothing to do with the data inside). It's the application that decides if it wants to lock a file or not. Ex:
Open a docx file in Word: Access denied (file in use)
Open a docx file in Wordpad: Success (no lock)
AFAIK it's impossible to detect 100% files being in use by ex. notepad which doesn't lock files.
There are many ways to delete files, but Remove-Item is as good as any of them.
Adding to Frode's point, nothing wrong with remove-item. Normal directory doesn't offer you much. Files hosted via windows file server provides session information might help you identify if a file is being used. If possible, you may implement a smart logic that excludes the files are in use.
In general, I'd recommend a work around that your powershell script check file's LastAccessTime, say, delete everything that hasn't been accessed for 24 hours
Get-ChildItem -path c:\ps | Where-Object {$_.LastAccessTime -lt (get-date).addDays(-1)}
The extreme way of protecting files, is using SCM and don't delete anything checked out. However this is not a friendly solution to average users.

Updating Batch files via Dropbox

So, there isn't anything big that I'm really going to use this for, but I've have made a little batch (.bat) program that I thought would be awesome if I had this feature in it.
I don't want anything that is going to mess up my LAN network, so try to make it as simple
as possible.
So my idea is that I want it so when the program starts it scans for an update (which will be found on Dropbox), then ask the user if they want to update, then it will install an update file and delete the old one. If anyone knows a way to do this safely, please tell me, thanks!
I have a tiny bit of an idea on how this is possible, but it is not very efficient. Thanks!
I assume you have a file on your computer and one on Dropbox and sometimes you want to edit it from another computer and then when you get back home and start up the program it will check whether the Dropbox file is more up to date than the one you have on your computer?
I think the easiest way would be to either use a special file name, like, myBatchFile_update.bat or something and then make your program check for that file in your Dropbox folder. If it's there, copy it and then rename it to myBatchFile.bat or something. Also rename update file. You may want to look up copy and xcopy and ren, first.
Another way would be to keep the "if updated" information inside of the file in a function (although it's hardly functions in batch). Or you could just keep another file called for example is_updated.bat where you keep information about whether it's updated or not. You echo something like set update=true (if it's updated) to the update file when it has updated and when you have edited the program you also edit the update file so that it says false. Then, when you need the information, you just call the update file.

Resources