Moving files in bulk to folders according to a key word in the file and folder name - file-move

I have several files named like this: Name 39W04150167 7015 0640 0000 2087 5834
I have several folders named like this: 39W04150167
I would like to transfer all files to their respective folders. The folder names and matching key word in the file names are unique and do not repeat.
Any ideas?
Thanks

Assuming your OS is in the unix family,
$ mv 39W04150167[0-9]* 39W04150167

Related

How to check whether a folder exists or not in gcp cloud storage out of 1 million folders

For example I have structure like this.
bucketname/checked/folder1/some files
bucketname/checked/folder2/some files
bucketname/checked/folder3/some files
bucketname/checked/folder4/some files
bucketname/checked/folder5/some files
bucketname/checked/folder6/some files
bucketname/checked/folder7/some files
bucketname/checked/folder8/some files
bucketname/checked/folder9/some files
bucketname/checked/folder10/some files
bucketname/checked/folder11/some files
......
......
bucketname/checked/folder-1million/some files
Now,
1. If I have to check whether folder99999 exists or not. So,what would be the best way to check it (we have information of folder name - folder99999) ?
2. If we simply check path that exists or not, and if not then it means, folder don't exists. would it work fine If we have millions of folders?
3. Which data structure gcp uses to retrieve the folder data ?
The true answer is this one provided by John: folder doesn't exist. All the files are stored at the root directory (bucket level) and the file name is the full path. By human convention, the / is the folder separator and the console display fake folders.
If you haven't files in a "folder", the "folder" doesn't exist, it's not interpreted/deduced from the name fully qualified path. The folder is not a Cloud Storage resource
It's also for that reason that you search only by path prefix
However, it depends what you want to check. If you exactly know which folder you want to check and validate, and if there is at least one file in it, you can directly list the files with the folder path as prefix.

Regex for all folders under one folder with a specific name

I have a EFS will thousands of folders, I need a regex that can find a folder called "NewFile" and select all the xml files in it which is in any of directory listed from the root directory.
i.e.
selects:
C:\dir1\something\something2\NewFile\some.xml
C:\dir1\something\NewFile\some2.xml
C:\dir1\NewFile\some3.xml
ignores:
C:\dir1\something\something.xml
I did some research and found this question
Regex match folder and all subfolders
But it was matching the folder name at the same level
So you want to match pathnames that contain NewFile followed by an XML file:
/NewFile\\.*\.xml$/

Delete only directories in maven

I am Using maven to create a war file
my folder <app> contains folder1 folder2 file1 ..
i want to get only file1
I have tried with the following..
<packagingExcludes>app/*/*.js</packagingExcludes>
any help here
The configuration is correct but the regex looks different.We use ** to indicate multiple directories and * to indicate an optional part of a file or directory name, as mentioned here. If I am not wrong, your regex looks like excluding all .js files in all folders of app, which is different from your requirement

How can I rename files of which I don't know the extension?

I have a directory with these files:
one.txt
two.mp3
three.bmp
Is there any way to rename files using MoveFile() but without specifying the extension of the file (all the files have different filenames)?
If not, how can I rename these files to anything I want, when I only know the
one
two
three
?
You'll have to use the underlying OS API to scan through the directory for files and compare each filename with your desired prefix. Here is another question that shows you how to list the contents of a directory in Windows.
Once you know prefix read the filelist of the directory and find a valid filename with that prefix, and use that filename with the function.

having file names and delete them

I want to have access to all files of a folder and have a list of them and work with them.
For example: there is a folder named "new folder" and consist of files : 1.txt and 2.txt
I don't know what are in the folder new folder. So I want a list of files in it .
Hence the questions are :
1- How can I have such this list?
2- How can I delete a file (e.g 2.txt) whether i know there is file with this name or not.
3- Is it possible to figure out has a txt file been used or not (whether it is empty or not)
thanks;
I'd use Boost filesystem to analyze folder content, and remove to delete the file. You will find in filesystem tutorial some sample that will ease your work.
edit: remove(path) it's available in boost filesystem.