Insert one and the same folder into multiple auto folders.

Violet -  
brucine Posted messages 24390 Registration date   Status Membre Last intervention   -

Hello,

I have a folder "Client Files" with 1940 subfolders named after the clients. I would like to insert 4 sub-subfolders into each subfolder without copying and pasting them 1940 times.

I would prefer not to use VBA, which I don't master.

However, I managed to create the "Client Files" folder and its subfolders using an Excel column and the cre_dossier.bat command after going through Notepad.

Maybe that's a clue?

If anyone has a simple solution...

Thank you in advance for your insights,

12 réponses

brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098
 

Hello,

In principle, this shouldn't create any particular issues in batch with a FOR loop that creates a subfolder in each of the folders, but I'm not sure I fully understand the request.

You want to create 4 identical, empty folders at level 3 within each of the level 2 folders?

The script would be more productive if you could provide an example of this hierarchy, with the path to the source folder called "Client Files" if I understood correctly, and made-up names for 2 clients and the 4 relevant subfolders.

0
UVMan
 

Hello,

First of all, thank you for your interest in my request, and yes, I don't necessarily express myself in computer language...

That being said, for example

Rank 1 Client Files

          Rank 2 Client A

                    Rank 3 Messaging

                    Rank 3 Route

                    Rank 3 Logistics

                    Rank 3 Freight

           Rank 2 Client B

                    Rank 3 Messaging

                    Rank 3 Route

                    Rank 3 Logistics

                    Rank 3 Freight

Etc ...

If ranks 1 and 2 are well created in my structure, it’s the rank 3s that I would like to insert "automatically" into the Rank 2 files in order not to reproduce 1940 copies!

And indeed, they are empty.

Is that clearer?

Thank you for your help,

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098
 

Hello,

I replaced the spaces with dashes and removed the acute accent; results with special characters are often unpredictable, and I assumed that the folder at rank 1 was located at the root of E:\

I suppose that the rank 2 folders already exist.

@echo off FOR /F %%a in ('dir /a:d /b /s "E:\Fiches_Clients"') DO SET CHEMIN=%%a & CALL :PROCESS GOTO EOF :PROCESS SET CHEMIN=%CHEMIN:~0,-1% MD %CHEMIN%\Messagerie MD %CHEMIN%\Route MD %CHEMIN%\Logistique MD %CHEMIN%\Affretement exit /b :EOF
0
UVMan
 

Wow, THANK YOU, the root is "Y", well I can handle that ...

But, do I need to place this encoding via "Command Prompt"?

Thank you for your response and the time spent.

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098
 

You naturally adjust your path accordingly, you copy what precedes into a new text file for example on the desktop, you rename it whatIwant.cmd and you click on it.

If you adopt the dash, you must of course be consistent and rename the folder Clients_Files.

0
UVMan
 

Text file created on desktop and named whatIwant.cmd / copy/paste executed with root change from E:\ to Y:\

But, I must be missing something, I set Y as the root, but the actual server name is:

commercial (\\192.168.2.XX)(Y:)

Is there a connection?

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098
 

I can't test, I'm retired, no more PC on the network.

Even if your drive is mapped to a letter Y, you can't address it directly in the command line.

If the name of the PC to reach is "commercial", try fully qualifying the network path in the form \\commercial\ or \\192.168.2.xx\ before the target folder path on this drive.

If that doesn’t suffice, you will probably need to access this drive using a prior NET USE command, username and password at the ready:

https://ss64.com/nt/net-use.html

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098 > brucine Posted messages 24390 Registration date   Status Membre Last intervention  
 

If you have physical access to the PC in question, rather than testing the configuration until it works, it's quicker to copy the script to the target machine via a USB key or through remote control and execute it locally.

0
UVMan
 

... Indeed, I was in the same line of thought after a few unsuccessful attempts, indeed the USB drive might be a quick solution (try it tomorrow, I don't have one on me), and what if I went directly through:

C:\Users\c.ch...\OneDrive - IMANY\Documents

I imagine that after IMANY\Documents, I should add \Client_Files? And voila?

0
UVMan
 

CONGRATULATIONS artist, it works with USB!

And a big THANK YOU for the time saved.

Maybe see you soon,

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098
 

Perfect and that's great, there's nothing more annoying than network permissions in the command line, especially when you can't test...

0
UVMan
 

Hello Brucine, great, the transfer and the creation of the subfolders worked.

So I have a new question to automate the following: Let's say,

I have 2 folders A & B,

A- Rank 1- "Grids"

Rank 2 - about 50 subfolders (clients) containing PRICE LIST files

B- Rank 1- The "Client_Folders" that I just created with the client names + the subfolders ...

So, rather than copying/pasting the files by client into the "Grid" folder to transfer them to the "Client_Folders" and the corresponding subfolder named after the client, I would like the transfer to happen directly.

For this, we will only take one root D:\ and of course the client names will be spelled identically from one file to another for matching.

Is this possible?

Thanks to the gray cells for the work provided!

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098
 

Hello,

once again a preliminary question, I am not sure I understood the hierarchy of the ranks correctly.

It is indeed (I have included photos as pricing) to move the files from the bottom to the root of the corresponding name at the top in bulk (without creating a subfolder for Pricing) and according to this structure, to be corrected if necessary?

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098 > brucine Posted messages 24390 Registration date   Status Membre Last intervention  
 

If that's the case, it gives this, you will replace E: with D:
Then destroy the empty source folder either manually or with a syntax
RD /S /Q

@echo off FOR /F %%a in ('dir /a:d /b /s "D:\Grilles"') DO SET GRILLES=%%a & CALL :PROCESS1 GOTO EOF :PROCESS1 SET GRILLES=%GRILLES:~0,-1% SET CLIENT=%GRILLES:~11% CALL :PROCESS2 exit /b :PROCESS2 MOVE %GRILLES%\*.* D:\Dossiers_Clients\%CLIENT% exit /b :EOF
0
UVMan
 

Hello brucine,

This collaboration is great!

Yes, I think you understood my request and the hierarchy of ranks seems to match.

I assume I need to use a text file to execute this function?

However, I am clueless about: "delete the file either by using the syntax
RD /S /Q"

I will run a small-scale test during the day.

Of course, I will keep you updated.

I will conduct a small-scale test to see if it works.

See you later,

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098
 

Hello,

No, it's an executable script toto.cmd, as before.

To test without any risks (simple simulation), use a second modified script as follows:

@echo off FOR /F %%a in ('dir /a:d /b /s "E:\Grilles"') DO SET GRILLES=%%a & CALL :PROCESS1 GOTO EOF :PROCESS1 SET GRILLES=%GRILLES:~0,-1% SET CLIENT=%GRILLES:~11% CALL :PROCESS2 exit /b :PROCESS2 rem MOVE %GRILLES%\*.* E:\Dossiers_Clients\%CLIENT% ROBOCOPY /L /MOV /NP /NS /NJH /NJS "%GRILLES%" "E:\Dossiers_Clients\%CLIENT%" pause exit /b :EOF

The ROBOCOPY command will give you an on-screen output of the "copied" files and their location without any action.

I assume that at the end of the operation the E:\Grilles folder and its subfolders become useless; either I delete them manually or I just write before :EOF

RD /S /Q "E:\Grilles"

0
UVMan
 

Ultimately, I am revisiting what I validated, as it is not quite right...

Attached is my structure of Excel FILES for pricing grids (ultimately, these are not subfolders, or the main folder would be the client's name).

The idea is to match an Excel file named for example "test 2023" with the root D:\"Grilles", in a folder named "test 2023" (same name) having the root D:\"Doccisers_Clients".

In other words, to place an file into a folder of the same name with the same root.

Is this clearer and feasible?

Thank you for all this brainstorming.

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098
 

What is well conceived can be clearly stated...

We need to remove the file extension (.xls) from the folder name, and I reiterate my concerns about spaces in file (and therefore folder) names; I assume the new folder should have the complete name of the source file, not a part that could be common (2023), otherwise it will become problematic, and that the target folders do not exist beforehand.

Also, be careful if the file names are very long, we might get rejected due to the excessive length of the path to the folder and then the target file.

Before starting once more, like this?

Before:


After:
 


 

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098 > brucine Posted messages 24390 Registration date   Status Membre Last intervention  
 

I removed 3 files between "before" and "after" to save time, but that doesn't change the question; if I hadn't done it, we would have found them "after".

0
UVMan
 

... Nicolas Boileau !

Attached, I think we will then speak the same language.

Is it better?

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098
 

Not sure yet.

For example, does the folder ALU AND PLASTIC 2023 already exist in Client_Folders (what a strange idea...) or do I need to create it before moving the file ALU AND PLASTIC 2023.xls from the Grids folder, which has exactly the same name?

A side question that matters and that we can't see since we can't see the extensions, we will need them to clean up, are they all xls files with an old version of Excel, not xlsx?

0
UVMan
 

So to be honest, I will first change the names of the .xls files to match the client folders in the Clients_Folders.

So NO NEED TO CREATE IT.

All the client names already exist in the "Clients_Folders" folder.

And yes, old version of Excel, so .xls for the files.

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098
 

If this is the final version, it's not complicated.

@echo off FOR /F %%a in ('dir /b "E:\Grilles"') DO SET FICHIER=%%a & CALL :PROCESS1 pause GOTO EOF :PROCESS1 SET FICHIER=%FICHIER:~0,-1% SET DOSSIER=%FICHIER:~0,-4% rem MOVE E:\Grilles\%FICHIER% E:\Dossiers_Clients\%DOSSIER% XCOPY /L /I /F "E:\Grilles\%FICHIER%" "E:\Dossiers_Clients\%DOSSIER%" exit /b :EOF

The pause, XCOPY, and the rem prefix lines are to test on the screen without doing anything.
If the result is satisfactory, remove pause and delete the XCOPY line (or remove the rem before MOVE and put it before XCOPY).

0
UVMan
 

Test carried out on a small scale.

Result: MAGIC!

I will extend it to all Files/Folders if I have time during the day.

A big THANK YOU for this support ...

"It's not complicated," says Brucine ... But still!!!

See you soon maybe ...

0
brucine Posted messages 24390 Registration date   Status Membre Last intervention   4 098
 

I forgot that there are spaces in your file names, if you don't want to have issues with the MOVE command, replace it with:

MOVE "E:\Grilles\%FICHIER%" "E:\Dossiers_Clients\%DOSSIER%"

and of course, remove the rem before executing it

0