Home > database >  How to do the folder name and the name of the file as a list of import to the Mysql database respect
How to do the folder name and the name of the file as a list of import to the Mysql database respect

Time:11-06

Consult BBS's friends, I like batch to do the folder name and file name respectively as a list of import to Mysql database,
I built a table date20170801A at present, the existing field code like this:
The CREATE TABLE ` date20170801A ` (
` TranID ` varchar (255) the DEFAULT NULL COMMENT 'order no.,
` Time ` varchar (255) the DEFAULT NULL COMMENT 'closing Time,
` Price ` varchar (255) the DEFAULT NULL COMMENT 'clinch a deal the Price,
` Volume ` varchar (255) the DEFAULT NULL COMMENT 'clinch a deal the number of shares,
` SaleOrderVolume ` varchar (255) the DEFAULT NULL COMMENT 'number of seller's deity,
` BuyOrderVolume ` varchar (255) the DEFAULT NULL COMMENT 'number of buyer's deity,
` Type ` varchar (255) the DEFAULT NULL COMMENT 'transaction Type,
` SaleOrderID ` varchar (255) the DEFAULT NULL COMMENT 'number seller deity,
` SaleOrderPrice ` varchar (255) the DEFAULT NULL COMMENT 'the seller to hang the unit price,
` BuyOrderID ` varchar (255) the DEFAULT NULL COMMENT 'number buyer deity,
` BuyOrderPrice ` varchar (255) the DEFAULT NULL COMMENT 'buyer to hang the unit price'
) ENGINE=MyISAM DEFAULT CHARSET=GBK;

Questions as follows:


How do I put it in more than 3000 date20170801A CSV import table, and the table automatically add two fields used to identify the folder name and file name


Hope ace to help me solve the great god, no matter how to even give a concrete train of thought, thank you!


File price inside the CSV file header has created tables in mysql with me date20170801A fields are consistent

CodePudding user response:

Field is good, but the database should be failed to get the function of the path,

CodePudding user response:

The ALTER TABLE ` date20170801A ` ADD COLUMN 'dir' VARCHAR (255) NULL AFTER 'buyer to hang the unit price, ADD the COLUMN' filename 'VARCHAR (255) NULL AFTER' dir '.
Path name and the name of the file with the program, suggest using python,
Dirs=OS. Listdir (' dir ')
For dir in dirs:
Files=OS. Listdir (dir)
For fileN in files:
SQL=...

CodePudding user response:

refer to the second floor long foot big fairy response:
ALTER TABLE ` date20170801A ` ADD COLUMN 'dir' VARCHAR (255) NULL AFTER 'the buyer to hang the unit price, ADD the COLUMN' filename 'VARCHAR (255) NULL AFTER' dir '.
Path name and the name of the file with the program, suggest using python,
Dirs=OS. Listdir (' dir ')
For dir in dirs:
Files=OS. Listdir (dir)
For fileN in files:
SQL=...

Thank you for your advice I've found expert help to solve this problem

CodePudding user response:

Can I also master ah, knot stick?
  • Related